File: waveManager.cpp

package info (click to toggle)
giada 0.15.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,700 kB
  • sloc: cpp: 30,043; sh: 1,056; makefile: 422; ansic: 1
file content (63 lines) | stat: -rw-r--r-- 1,663 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <memory>
#include "../src/core/waveManager.h"
#include "../src/core/wave.h"
#include "../src/core/const.h"
#include <catch.hpp>


using std::string;
using namespace giada::m;


#define G_SAMPLE_RATE 44100
#define G_BUFFER_SIZE 4096
#define G_CHANNELS 2


TEST_CASE("waveManager")
{
  /* Each SECTION the TEST_CASE is executed from the start. Any code between 
  this comment and the first SECTION macro is exectuted before each SECTION. */

  Wave* w;

  SECTION("test creation")
  {
    int res = waveManager::create("tests/resources/test.wav", &w);
    std::unique_ptr<Wave> wave(w);
    
    REQUIRE(res == G_RES_OK);
    REQUIRE(wave->getRate() == G_SAMPLE_RATE);
    REQUIRE(wave->getChannels() == G_CHANNELS);
    REQUIRE(wave->isLogical() == false);
    REQUIRE(wave->isEdited() == false);
  }

  SECTION("test recording")
  {
    waveManager::createEmpty(G_BUFFER_SIZE, G_MAX_IO_CHANS, G_SAMPLE_RATE, 
      "test.wav", &w);
    std::unique_ptr<Wave> wave(w);

    REQUIRE(wave->getRate() == G_SAMPLE_RATE);
    REQUIRE(wave->getSize() == G_BUFFER_SIZE);
    REQUIRE(wave->getChannels() == G_CHANNELS);
    REQUIRE(wave->isLogical() == true);
    REQUIRE(wave->isEdited() == false);
  }

  SECTION("test resampling")
  {
    waveManager::create("tests/resources/test.wav", &w);
    std::unique_ptr<Wave> wave(w);

    int oldSize = wave->getSize();
    waveManager::resample(wave.get(), 1, G_SAMPLE_RATE * 2);
    
    REQUIRE(wave->getRate() == G_SAMPLE_RATE * 2);
    REQUIRE(wave->getSize() == oldSize * 2);
    REQUIRE(wave->getChannels() == G_CHANNELS);
    REQUIRE(wave->isLogical() == false);
    REQUIRE(wave->isEdited() == false);
  }
}