You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/api-c-audio.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ void play() {
39
39
40
40
//creates a mon-audio channel buffer at our given SAMPLE_RATE
41
41
// and square-wave data we generated
42
-
long node_id = twr_audio_from_samples(1, SAMPLE_RATE, wave, length);
42
+
long node_id = twr_audio_from_float_pcm(1, SAMPLE_RATE, wave, length);
43
43
44
44
//plays the square wave
45
45
// Can be played multiple times, and is only freed on twr_audio_free
@@ -50,7 +50,7 @@ void play() {
50
50
## Overview
51
51
The Audio API is part a twr-wasm library that can be accessed via `#include "twr-audio.h"`. It has two main methods to play audio: from raw PCM data and from a URL.
52
52
53
-
Raw PCM data can be initialized via `twr_audio_from_samples` or `twr_audio_load`. `twr_audio_from_samples` takes in the PCM data as an array of floats between -1.0 and 1.0. `twr_audio_load`, on the other hand, reads the PCM data from an audio file that is specified by a URL. This method does not stream the audio, so it might take some time to read the file (depending how long the file is). Each function returns an integer `node_id` that identifies the loaded PCM data. Once the PCM data is initialized, it can be played via functions like `twr_audio_play`, `twr_audio_play_range`, `twr_audio_play_sync`, and `twr_audio_play_range_sync`. The play functions can be called multiple times for each audio ID.
53
+
Raw PCM data can be initialized via `twr_audio_from_<type>_pcm` or `twr_audio_load`. There are multiple types for `twr_audio_from_<type>_pcm`. These types include Float, 8bit, 16bit, and 32bit. Float takes in values between -1.0 and 1.0. Meanwhile, the 8bit, 16bit, and 32bit versions take them in as signed numbers between their minimum and maximum values. `twr_audio_load`, on the other hand, reads the PCM data from an audio file that is specified by a URL. This method does not stream the audio, so it might take some time to read the file (depending how long the file is). Each function returns an integer `node_id` that identifies the loaded PCM data. Once the PCM data is initialized, it can be played via functions like `twr_audio_play`, `twr_audio_play_range`, `twr_audio_play_sync`, and `twr_audio_play_range_sync`. The play functions can be called multiple times for each audio ID.
54
54
55
55
You can also play audio directly from a URL. Unlike `twr_audio_load`, the url is initialized directly into an `HTMLAudioElement` which streams the audio and starts playback immediately.
56
56
@@ -65,7 +65,15 @@ Functions that end in `_sync` are for use with `twrWamModuleAsync`, and are sync
65
65
These are the current Audio APIs available in C/C++:
66
66
67
67
~~~c
68
-
longtwr_audio_from_samples(long num_channels, long sample_rate, float* data, long singleChannelDataLen);
68
+
longtwr_audio_from_float_pcm(long num_channels, long sample_rate, float* data, long singleChannelDataLen);
69
+
long twr_audio_from_8bit_pcm(long number_channels, long sample_rate, char* data, long singleChannelDataLen);
70
+
long twr_audio_from_16bit_pcm(long number_channels, long sample_rate, short* data, long singleChannelDataLen);
71
+
long twr_audio_from_32bit_pcm(long number_channels, long sample_rate, int* data, long singleChannelDataLen);
0 commit comments