-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
76 lines (62 loc) · 3.06 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdbool.h>
#include "SLES/OpenSLES.h"
#include "SLES/OpenSLES_Android.h"
short *playBuffer = NULL;
FILE *file = NULL;
static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
{
int bytes = fread(playBuffer, 1, 2048 * sizeof(short), file);
(*bq)->Enqueue(bq, playBuffer,bytes);
}
int main(int argc, char* const argv[])
{
SLresult result;
SLObjectItf engineObject = NULL;
result = slCreateEngine( &engineObject, 0, NULL, 0, NULL, NULL);
result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
SLEngineItf engineEngine;
result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, (void*)&engineEngine);
SLDataFormat_PCM format_pcm = { SL_DATAFORMAT_PCM, 2, SL_SAMPLINGRATE_44_1,
SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT, SL_BYTEORDER_LITTLEENDIAN };
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
SLDataSource audioSrc = {&loc_bufq, &format_pcm};
SLObjectItf outputMixObject = NULL;
result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL);
fprintf(stderr, "result %d\n", result);
result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
fprintf(stderr, "result %d\n", result);
SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
SLDataSink audioSnk = {&loc_outmix, NULL};
SLObjectItf bqPlayerObject = NULL;
SLPlayItf bqPlayerPlay;
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
const SLInterfaceID ids1[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE};
const SLboolean req1[] = {SL_BOOLEAN_TRUE};
fprintf(stderr, "result %d\n", result);
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, 1, ids1, req1);
fprintf(stderr, "result %d\n", result);
result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
fprintf(stderr, "result %d\n", result);
result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);
fprintf(stderr, "result %d\n", result);
result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue);
fprintf(stderr, "result %d\n", result);
result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL);
//result = (*bqPlayerObject)->RegisterCallback(bqPlayerObject, bqPlayerCallback, NULL);
fprintf(stderr, "result %d\n", result);
result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
fprintf(stderr, "result %d\n", result);
// 1024 frame * 2 channel
playBuffer = (short *) calloc(1024 * 2, sizeof(short));
(*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, playBuffer, 2048*sizeof(short));
//bqPlayerBufferQueue->Enqueue(bqPlayerBufferQueue, NULL, );
file = fopen("test_pcm_s16le.pcm", "r");
usleep(60000000);
return 0;
}