-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathaccompany_decoder_controller.cpp
More file actions
49 lines (43 loc) · 1.46 KB
/
accompany_decoder_controller.cpp
File metadata and controls
49 lines (43 loc) · 1.46 KB
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
#include "accompany_decoder_controller.h"
#define LOG_TAG "AccompanyDecoderController"
AccompanyDecoderController::AccompanyDecoderController() {
accompanyDecoder = NULL;
pcmFile = NULL;
}
AccompanyDecoderController::~AccompanyDecoderController() {
}
int AccompanyDecoderController::Init(const char* accompanyPath, const char* pcmFilePath) {
//初始化两个decoder
AccompanyDecoder* tempDecoder = new AccompanyDecoder();
int accompanyMetaData[2];
tempDecoder->getMusicMeta(accompanyPath, accompanyMetaData);
delete tempDecoder;
//初始化伴奏的采样率
accompanySampleRate = accompanyMetaData[0];
int accompanyByteCountPerSec = accompanySampleRate * CHANNEL_PER_FRAME * BITS_PER_CHANNEL / BITS_PER_BYTE;
accompanyPacketBufferSize = (int) ((accompanyByteCountPerSec / 2) * 0.2);
accompanyDecoder = new AccompanyDecoder();
int ret= accompanyDecoder->init(accompanyPath, accompanyPacketBufferSize);
pcmFile = fopen(pcmFilePath, "wb+");
return pcmFile!=NULL&&ret==1?1:-1;
}
void AccompanyDecoderController::Decode() {
while(true) {
AudioPacket* accompanyPacket = accompanyDecoder->decodePacket();
if(-1 == accompanyPacket->size) {
break;
}
fwrite(accompanyPacket->buffer, sizeof(short), accompanyPacket->size, pcmFile);
}
}
void AccompanyDecoderController::Destroy() {
if (NULL != accompanyDecoder) {
accompanyDecoder->destroy();
delete accompanyDecoder;
accompanyDecoder = NULL;
}
if(NULL != pcmFile) {
fclose(pcmFile);
pcmFile = NULL;
}
}