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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include <algorithm>
#include <string>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#define BKNI_TRACK_MALLOCS 1
#include "nexus_platform.h"
#include "nexus_platform_features.h"
#include "bstd.h"
#include "bkni.h"
#include "bkni_multi.h"
#include "nexus_audio_playback.h"
#include "nexus_audio_output.h"
#include "nexus_audio_input.h"
#include "nexus_audio_decoder.h"
#include "nexus_audio_mixer.h"
#include "nexus_stc_channel.h"
#include "nexus_pid_channel.h"
#include "nexus_parser_band.h"
#include "device_nexus.h"
#include "debug.h"
namespace audiere {
NexusAudioDevice*
NexusAudioDevice::create(const ParameterList& parameters) {
bool initPlatform = parameters.getBoolean("initPlatform", false);
BKNI_EventHandle event;
NEXUS_PlatformConfiguration config;
NEXUS_AudioPlaybackHandle playback;
NEXUS_AudioPlaybackStartSettings playbackSettings;
NexusAudioDevice *device;
if (initPlatform)
NEXUS_Platform_Init(NULL);
NEXUS_Platform_GetConfiguration(&config);
playback = NEXUS_AudioPlayback_Open(0, NULL);
if (!playback)
{
ADR_LOG("Unable to open playback channel\n");
return 0;
}
NEXUS_AudioOutput_AddInput(NEXUS_AudioDac_GetConnector(config.outputs.audioDacs[0]),
NEXUS_AudioPlayback_GetConnector(playback));
NEXUS_AudioPlayback_GetDefaultStartSettings(&playbackSettings);
playbackSettings.sampleRate = 44100;
playbackSettings.bitsPerSample = 16;
playbackSettings.signedData = true;
playbackSettings.stereo = true;
playbackSettings.dataCallback.callback = DataCallback;
playbackSettings.dataCallback.param = 0;
BKNI_CreateEvent(&event);
device = new NexusAudioDevice(playback, event, 44100, 4096);
playbackSettings.dataCallback.context = device;
NEXUS_AudioPlayback_Start(playback, &playbackSettings);
return device;
}
void NexusAudioDevice::DataCallback(void *pParam1, int param2)
{
if (!pParam1)
return;
NexusAudioDevice *device = (NexusAudioDevice*)pParam1;
if (device->m_event)
BKNI_SetEvent(device->m_event);
}
NexusAudioDevice::NexusAudioDevice(NEXUS_AudioPlaybackHandle playback,
BKNI_EventHandle event,
int rate,
int buffer_size)
: MixerDevice(rate), m_event(event), m_playback(playback), m_rate(rate)
{
m_buffer_size = buffer_size;
m_buffer = new char [buffer_size];
}
NexusAudioDevice::~NexusAudioDevice() {
ADR_GUARD("NexusAudioDevice::~NexusAudioDevice");
NEXUS_PlatformConfiguration config;
NEXUS_Platform_GetConfiguration(&config);
NEXUS_AudioPlayback_Stop(m_playback);
NEXUS_AudioOutput_RemoveAllInputs(NEXUS_AudioDac_GetConnector(config.outputs.audioDacs[0]));
NEXUS_AudioPlayback_Close(m_playback);
BKNI_DestroyEvent(m_event);
delete [] m_buffer;
}
void ADR_CALL
NexusAudioDevice::update() {
int sample_len;
size_t sample_left;
char* sample_buf;
sample_buf = m_buffer;
sample_len = m_buffer_size / 4;
sample_left = read(sample_len, sample_buf);
while (sample_left > 0) {
int16_t *buffer;
size_t buffersize;
BERR_Code err;
/* Check available buffer space */
err = NEXUS_AudioPlayback_GetBuffer(m_playback, (void **)&buffer, &buffersize);
if (err)
break;
if (buffersize) {
/* Copy samples into buffer */
buffersize /= 4;
if (buffersize > sample_left)
buffersize = sample_left;
memcpy(buffer, sample_buf, buffersize * 4);
err = NEXUS_AudioPlayback_ReadComplete(m_playback, buffersize * 4);
if (err)
break;
sample_buf += buffersize * 4;
sample_left -= buffersize;
} else {
/* Wait for data callback */
err = BKNI_WaitForEvent(m_event, 1000);
if (err)
break;
}
}
}
const char* ADR_CALL
NexusAudioDevice::getName() {
return "nexus";
}
}
|