Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ukaelAudio program
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <portaudio.h>
- #include "ukaelH/ukaelTypedefC.h"
- #include "ukaelH/ukaelWaveC.h"
- #include "ukaelH/ukaelToneC.h"
- static const uint8_t PLAYAUDIO = 1;
- int main( int argc, char *argv[] ) {
- ENTROPY^=rand();
- PaError err;
- PaStream* stream;
- AudioData sample[MAX_CHANNELS];
- WaveArg wargs = {
- .time = DEFAULT_AMPLITUDE,
- .freq = (Frac){127,1},
- .u8arg = {0,0,0,0},
- .u16arg = {0,0,0,0}
- };
- //allocate
- sample[0].size = BUFFER_SIZE;
- sampleAlloc(&sample[0]);
- // Generate the wave
- wargs.u8arg[0]=6;
- wargs.u8arg[1]=DEFAULT_AMPLITUDE;
- generateTone(&sample[0], 255, "testing", &wargs );
- AudioData PAudioData;
- PAudioData.size = BUFFER_SIZE;
- PAudioData.position = 0;
- sampleAlloc(&PAudioData);
- sampleCopy(&PAudioData,&sample[0]);
- audioDataToBin("audio.bin", &PAudioData);
- if(PLAYAUDIO && PAudioData.size){
- // Initialize PortAudio
- err = Pa_Initialize();
- if (err != paNoError) {
- printf("Failed to initialize PortAudio: %s\n", Pa_GetErrorText(err));
- return 1;
- }
- // Open the default output stream
- err = Pa_OpenDefaultStream(&stream, 0, 1, paUInt8, SAMPLE_RATE,
- FRAMES_PER_BUFFER, audioCallback, &PAudioData);
- if (err != paNoError) {
- printf("Failed to open stream: %s\n", Pa_GetErrorText(err));
- Pa_Terminate();
- return 1;
- }
- // Start the stream
- err = Pa_StartStream(stream);
- if (err != paNoError) {
- printf("Failed to start stream: %s\n", Pa_GetErrorText(err));
- Pa_CloseStream(stream);
- Pa_Terminate();
- return 1;
- }
- // Wait for the stream to finish
- printf("Playing audio...\n");
- Pa_Sleep((PAudioData.size)/SAMPLE_RATE*1000);
- // Stop and close the stream
- err = Pa_StopStream(stream);
- if (err != paNoError) {
- printf("Failed to stop stream: %s\n", Pa_GetErrorText(err));
- }
- err = Pa_CloseStream(stream);
- if (err != paNoError) {
- printf("Failed to close stream:%s\n", Pa_GetErrorText(err));
- }
- // Terminate PortAudio
- Pa_Terminate();
- }
- sampleFree(&sample[0]);
- sampleFree(&PAudioData);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement