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
153
154
155
156
157
158
159
160
|
#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);
NEXUS_PlatformConfiguration config;
NEXUS_AudioPlaybackHandle playback;
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));
device = new NexusAudioDevice(playback, 44100, 4096);
char buf[64];
snprintf(buf, sizeof(buf), "%ld", (unsigned long)playback);
setenv ("AUDIERE_NEXUS_PLAYBACK", buf, 1);
snprintf(buf, sizeof(buf), "%ld", (unsigned long)&device->m_playbackSettings);
setenv ("AUDIERE_NEXUS_PLAYBACK_SETTINGS", buf, 1);
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,
int rate,
int buffer_size)
: MixerDevice(rate), m_playback(playback), m_rate(rate)
{
m_buffer_size = buffer_size;
m_buffer = new char [buffer_size];
NEXUS_AudioPlayback_GetDefaultStartSettings(&m_playbackSettings);
m_playbackSettings.sampleRate = 44100;
m_playbackSettings.bitsPerSample = 16;
m_playbackSettings.signedData = true;
m_playbackSettings.stereo = true;
m_playbackSettings.dataCallback.callback = DataCallback;
m_playbackSettings.dataCallback.param = 0;
m_playbackSettings.dataCallback.context = this;
BKNI_CreateEvent(&m_event);
NEXUS_AudioPlayback_Start(playback, &m_playbackSettings);
}
NexusAudioDevice::~NexusAudioDevice() {
ADR_GUARD("NexusAudioDevice::~NexusAudioDevice");
NEXUS_PlatformConfiguration config;
NEXUS_Platform_GetConfiguration(&config);
unsetenv ("AUDIERE_NEXUS_PLAYBACK");
NEXUS_AudioPlayback_Stop(m_playback);
#if NEXUS_NUM_HDMI_OUTPUTS
NEXUS_AudioOutput_RemoveAllInputs(NEXUS_HdmiOutput_GetAudioConnector(config.outputs.hdmi[0]));
#endif
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";
}
}
|