Skip to content

Commit 3342635

Browse files
authored
Merge pull request hathach#1825 from HiFiPhile/mic_test
Minor audio_test example fix.
2 parents 9e16e90 + 8a1184e commit 3342635

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

examples/device/audio_test/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX+1];
7171
audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
7272

7373
// Audio test data
74-
uint16_t test_buffer_audio[CFG_TUD_AUDIO_EP_SZ_IN/2];
74+
uint16_t test_buffer_audio[(CFG_TUD_AUDIO_EP_SZ_IN - 2) / 2];
7575
uint16_t startVal = 0;
7676

7777
void led_blinking_task(void);
@@ -400,7 +400,7 @@ bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, uint8_t ep_in, u
400400
(void) ep_in;
401401
(void) cur_alt_setting;
402402

403-
tud_audio_write ((uint8_t *)test_buffer_audio, CFG_TUD_AUDIO_EP_SZ_IN);
403+
tud_audio_write ((uint8_t *)test_buffer_audio, CFG_TUD_AUDIO_EP_SZ_IN - 2);
404404

405405
return true;
406406
}
@@ -413,7 +413,7 @@ bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uin
413413
(void) ep_in;
414414
(void) cur_alt_setting;
415415

416-
for (size_t cnt = 0; cnt < CFG_TUD_AUDIO_EP_SZ_IN/2; cnt++)
416+
for (size_t cnt = 0; cnt < (CFG_TUD_AUDIO_EP_SZ_IN - 2) / 2; cnt++)
417417
{
418418
test_buffer_audio[cnt] = startVal++;
419419
}

examples/device/audio_test/src/plot_audio_samples.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import matplotlib.pyplot as plt
33
import numpy as np
44
import platform
5+
import csv
56

67
if __name__ == '__main__':
78

@@ -31,4 +32,7 @@
3132
plt.ylabel('Amplitude')
3233
plt.title('MicNode')
3334
plt.show()
35+
36+
samples = np.array(myrecording)
37+
np.savetxt('Output.csv', samples, delimiter=",", fmt='%s')
3438

examples/device/audio_test/src/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extern "C" {
114114
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
115115
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below
116116
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
117-
#define CFG_TUD_AUDIO_EP_SZ_IN 48 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 48 Samples (48 kHz) x 2 Bytes/Sample x 1 Channel
117+
#define CFG_TUD_AUDIO_EP_SZ_IN (48 + 1) * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 48 Samples (48 kHz) x 2 Bytes/Sample x CFG_TUD_AUDIO_N_CHANNELS_TX Channels - One extra sample is needed for asynchronous transfer adjustment, see feedback EP
118118
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN // Maximum EP IN size for all AS alternate settings used
119119
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ CFG_TUD_AUDIO_EP_SZ_IN + 1
120120

0 commit comments

Comments
 (0)