-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_player.c
58 lines (48 loc) · 1.6 KB
/
audio_player.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// #include "audio_player.h"
// #include <stdio.h>
// #include <stdlib.h>
// #include <mpg123.h>
// #include <portaudio.h>
// #define SAMPLE_RATE 44100
// #define FRAMES_PER_BUFFER 256
// mpg123_handle *mpg123;
// PaStream *stream;
// // Initialize the audio player
// void init_audio_player() {
// mpg123_init();
// mpg123 = mpg123_new(NULL, NULL);
// mpg123_open(mpg123);
// mpg123_format_none(mpg123);
// mpg123_format(mpg123, SAMPLE_RATE, MPG123_MONO, MPG123_ENC_SIGNED_16);
// Pa_Initialize();
// Pa_OpenDefaultStream(&stream, 0, 1, paInt16, SAMPLE_RATE, FRAMES_PER_BUFFER, NULL, NULL);
// Pa_StartStream(stream);
// }
// // Play audio from an MP3 file
// void play_audio(const char* audioFile) {
// int error;
// size_t bufferSize;
// unsigned char buffer[FRAMES_PER_BUFFER * 2]; // Stereo
// FILE *file = fopen(audioFile, "rb");
// if (file == NULL) {
// fprintf(stderr, "Failed to open audio file: %s\n", audioFile);
// return;
// }
// while (1) {
// error = mpg123_read(mpg123, buffer, sizeof(buffer), &bufferSize);
// if (error == MPG123_DONE) {
// break;
// }
// Pa_WriteStream(stream, buffer, bufferSize / 2); // Divide by 2 for stereo to mono conversion
// }
// fclose(file);
// }
// // Clean up and close the audio player
// void shutdown_audio_player() {
// mpg123_close(mpg123);
// mpg123_delete(mpg123);
// mpg123_exit();
// Pa_StopStream(stream);
// Pa_CloseStream(stream);
// Pa_Terminate();
// }