Mercurial > hg > svcore
comparison data/fileio/test/AudioTestData.h @ 1450:a12fd0456f0c streaming-csv-writer
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 17 Apr 2018 10:35:42 +0100 |
parents | 48e9f538e6e9 |
children |
comparison
equal
deleted
inserted
replaced
1449:deabf9fd3d28 | 1450:a12fd0456f0c |
---|---|
36 */ | 36 */ |
37 class AudioTestData | 37 class AudioTestData |
38 { | 38 { |
39 public: | 39 public: |
40 AudioTestData(double rate, int channels) : | 40 AudioTestData(double rate, int channels) : |
41 m_channelCount(channels), | 41 m_channelCount(channels), |
42 m_duration(2.0), | 42 m_duration(2.0), |
43 m_sampleRate(rate), | 43 m_sampleRate(rate), |
44 m_sinFreq(600.0), | 44 m_sinFreq(600.0), |
45 m_pulseFreq(2) | 45 m_pulseFreq(2) |
46 { | 46 { |
47 m_frameCount = lrint(m_duration * m_sampleRate); | 47 m_frameCount = lrint(m_duration * m_sampleRate); |
48 m_data = new float[m_frameCount * m_channelCount]; | 48 m_data = new float[m_frameCount * m_channelCount]; |
49 m_pulseWidth = 0.01 * m_sampleRate; | 49 m_pulseWidth = 0.01 * m_sampleRate; |
50 generate(); | 50 generate(); |
51 } | 51 } |
52 | 52 |
53 ~AudioTestData() { | 53 ~AudioTestData() { |
54 delete[] m_data; | 54 delete[] m_data; |
55 } | 55 } |
56 | 56 |
57 void generate() { | 57 void generate() { |
58 | 58 |
59 double hpw = m_pulseWidth / 2.0; | 59 double hpw = m_pulseWidth / 2.0; |
60 | 60 |
61 for (int i = 0; i < m_frameCount; ++i) { | 61 for (int i = 0; i < m_frameCount; ++i) { |
62 for (int c = 0; c < m_channelCount; ++c) { | 62 for (int c = 0; c < m_channelCount; ++c) { |
63 | 63 |
64 double s = 0.0; | 64 double s = 0.0; |
65 | 65 |
66 if (c == 0) { | 66 if (c == 0) { |
67 | 67 |
68 double phase = (i * m_sinFreq * 2.0 * M_PI) / m_sampleRate; | 68 double phase = (i * m_sinFreq * 2.0 * M_PI) / m_sampleRate; |
69 s = sin(phase); | 69 s = sin(phase); |
70 | 70 |
71 } else if (c == 1) { | 71 } else if (c == 1) { |
72 | 72 |
73 int pulseNo = int((i * m_pulseFreq) / m_sampleRate); | 73 int pulseNo = int((i * m_pulseFreq) / m_sampleRate); |
74 int index = int(round((i * m_pulseFreq) - | 74 int index = int(round((i * m_pulseFreq) - |
75 (m_sampleRate * pulseNo))); | 75 (m_sampleRate * pulseNo))); |
76 if (index < m_pulseWidth) { | 76 if (index < m_pulseWidth) { |
77 s = 1.0 - fabs(hpw - index) / hpw; | 77 s = 1.0 - fabs(hpw - index) / hpw; |
78 if (pulseNo % 2) s = -s; | 78 if (pulseNo % 2) s = -s; |
79 } | 79 } |
80 | 80 |
81 } else { | 81 } else { |
82 | 82 |
83 s = c / 20.0; | 83 s = c / 20.0; |
84 } | 84 } |
85 | 85 |
86 m_data[i * m_channelCount + c] = float(s); | 86 m_data[i * m_channelCount + c] = float(s); |
87 } | 87 } |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 float *getInterleavedData() const { | 91 float *getInterleavedData() const { |
92 return m_data; | 92 return m_data; |
93 } | 93 } |
94 | 94 |
95 sv_frame_t getFrameCount() const { | 95 sv_frame_t getFrameCount() const { |
96 return m_frameCount; | 96 return m_frameCount; |
97 } | 97 } |
98 | 98 |
99 int getChannelCount() const { | 99 int getChannelCount() const { |
100 return m_channelCount; | 100 return m_channelCount; |
101 } | 101 } |
102 | 102 |
103 sv_samplerate_t getSampleRate () const { | 103 sv_samplerate_t getSampleRate () const { |
104 return m_sampleRate; | 104 return m_sampleRate; |
105 } | 105 } |
106 | 106 |
107 double getDuration() const { // seconds | 107 double getDuration() const { // seconds |
108 return m_duration; | 108 return m_duration; |
109 } | 109 } |
110 | 110 |
111 private: | 111 private: |
112 float *m_data; | 112 float *m_data; |
113 sv_frame_t m_frameCount; | 113 sv_frame_t m_frameCount; |