@@ -12,71 +12,16 @@ You can use the USBAudio interface to send and receive audio data over USB. Once
12
12
13
13
This example outputs an audio square wave over USB.
14
14
15
- ``` C++ TODO
16
- // This example simply generates a square wave.
17
- // Use a program like Audacity to record and hear the square wave, or route microphone input to output device.
18
- #include " mbed.h"
19
- #include " USBAudio.h"
20
- #include < math.h>
21
-
22
- int16_t square_wave (uint32_t freq_hz, uint16_t amplitude, float time_s)
23
- {
24
- float period = (float)1 / freq_hz;
25
- if (fmod(time_s, period) > period / 2) {
26
- return amplitude / 2;
27
- } else {
28
- return -(amplitude / 2);
29
- }
30
- }
31
-
32
- int main() {
33
- uint32_t tx_freq = 16000;
34
- USBAudio audio(true, 8000, 2, tx_freq, 1, 10, 0x7bb8, 0x1112, 0x0100);
35
- float cur_time = 0;
36
- while (true) {
37
- uint16_t samples[ 64] ;
38
- for (int i = 0; i < 64; i++) {
39
- samples[ i] = square_wave(100, 5000, cur_time);
40
- cur_time += 1.0 / tx_freq;
41
- }
42
- if (!audio.write((uint8_t * )&samples, sizeof(samples))) {
43
- audio.write_wait_ready();
44
- }
45
- }
46
- }
47
-
48
- ```
15
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_square_wave )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_square_wave/main.cpp )
49
16
50
17
### USBAudio loopback example
51
18
52
19
This example loops input audio to the Mbed board back to the host PC, so that you may record the audio or listen to it through headphones or speakers.
53
20
54
- ```C++ TODO
55
- // Audio loopback example use:
56
- // 1. Select "Mbed Audio" as your PC's default speaker and microphone devices.
57
- // 2. Play some sound (YouTube, audio file, etc.) on your PC with Mbed board connected to your PC via the target's USB.
58
- // 3. Record using a program such as Audacity with the Mbed board connected and with the audio on your PC playing.
59
- // 4. The audio that is playing on your PC will be recorded by Audacity via USB loopback.
60
- #include "mbed.h"
61
- #include "USBAudio.h"
62
-
63
- int main() {
64
-
65
- USBAudio audio(true, 44100, 2, 44100, 2);
66
-
67
- printf("Looping audio\r\n");
68
- static uint8_t buf[128];
69
- while (true) {
70
- if (!audio.read(buf, sizeof(buf))) {
71
- memset(buf, 0, sizeof(buf));
72
- }
73
- audio.write(buf, sizeof(buf));
74
- }
75
- }
76
- ```
21
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_loopback_example )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_loopback_example/main.cpp )
77
22
78
23
### USBAudio play sound data example
79
24
80
25
This example loads raw audio data to your board's flash. That data then plays on the host PC over USB. We have tested this example with the NXP FRDM-K64F, which has 1 MB of flash memory. If you are using a board that has less than 1 MB of flash memory, delete data from the end of the ` data ` array, and set ` NUM_ELEMENTS ` accordingly until the program size is small enough to flash without exceeding storage. Follow the link below, and click Ctrl + s to save the raw code view for ` main.cpp ` .
81
26
82
- #### [ main.cpp] ( https://raw.githubusercontent. com/mrcoulter45 /mbed-os-5-docs/USBAudio.md_additions/docs/reference/api/usb/Audio_Play_Sound_Data .cpp )
27
+ #### [ main.cpp] ( https://github. com/ARMmbed /mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_play_sound/main .cpp )
0 commit comments