Subversion Repositories Kolibri OS

Rev

Rev 6133 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6133 Rev 6144
1
#include 
1
#include 
2
#include 
2
#include 
3
#include 
3
#include 
4
#include 
4
#include 
5
#include 
5
#include 
6
#include 
6
#include 
7
#include 
7
#include 
8
 
8
 
9
#include "winlib/winlib.h"
9
#include "winlib/winlib.h"
10
#include "sound.h"
10
#include "sound.h"
11
#include "fplay.h"
11
#include "fplay.h"
12
 
12
 
13
 
13
 
14
astream_t astream;
14
astream_t astream;
15
 
15
 
16
extern uint8_t *decoder_buffer;
16
extern uint8_t *decoder_buffer;
17
int resampler_size;
17
int resampler_size;
18
volatile int sound_level_0;
18
volatile int sound_level_0;
19
volatile int sound_level_1;
19
volatile int sound_level_1;
20
 
20
 
21
volatile enum player_state player_state;
21
volatile enum player_state player_state;
22
volatile enum player_state decoder_state;
22
volatile enum player_state decoder_state;
23
volatile enum player_state sound_state;
23
volatile enum player_state sound_state;
24
 
24
 
25
static SNDBUF hBuff;
25
static SNDBUF hBuff;
26
 
26
 
27
static int snd_format;
27
static int snd_format;
28
int sample_rate;
28
int sample_rate;
29
 
29
 
30
static uint32_t samples_written = 0;
30
static uint32_t samples_written = 0;
31
double audio_base = -1.0;
31
 
32
 
-
 
33
double get_audio_base();
-
 
34
 
-
 
35
int init_audio(int format)
32
int init_audio(int format)
36
{
33
{
37
    int    err;
34
    int    err;
38
    int    version =-1;
35
    int    version =-1;
39
    char  *errstr;
36
    char  *errstr;
40
 
37
 
41
    if((err = InitSound(&version)) !=0 )
38
    if((err = InitSound(&version)) !=0 )
42
    {
39
    {
43
        errstr = "Sound service not installed\n\r";
40
        errstr = "Sound service not installed\n\r";
44
        goto exit_whith_error;
41
        goto exit_whith_error;
45
    };
42
    };
46
 
43
 
47
    if( (SOUND_VERSION>(version&0xFFFF)) ||
44
    if( (SOUND_VERSION>(version&0xFFFF)) ||
48
        (SOUND_VERSION<(version >> 16)))
45
        (SOUND_VERSION<(version >> 16)))
49
    {
46
    {
50
        errstr = "Sound service version mismatch\n\r";
47
        errstr = "Sound service version mismatch\n\r";
51
        goto exit_whith_error;
48
        goto exit_whith_error;
52
    }
49
    }
53
 
50
 
54
    snd_format = format;
51
    snd_format = format;
55
 
52
 
56
    create_thread(audio_thread, 0, 163840);
53
    create_thread(audio_thread, 0, 163840);
57
 
54
 
58
    return 1;
55
    return 1;
59
 
56
 
60
exit_whith_error:
57
exit_whith_error:
61
 
58
 
62
    printf(errstr);
59
    printf(errstr);
63
    return 0;
60
    return 0;
64
};
61
};
65
 
62
 
66
void set_audio_volume(int left, int right)
63
void set_audio_volume(int left, int right)
67
{
64
{
68
    SetVolume(hBuff, left, right);
65
    SetVolume(hBuff, left, right);
69
};
66
};
70
 
67
 
71
static uint64_t samples_lost;
68
static uint64_t samples_lost;
72
static double  audio_delta;
69
static double  audio_delta;
73
static double  last_time_stamp;
70
static double  last_time_stamp;
74
 
71
 
75
 
72
 
76
double get_master_clock(void)
73
double get_master_clock(void)
77
{
74
{
78
    double tstamp;
75
    double tstamp;
79
 
76
 
80
    GetTimeStamp(hBuff, &tstamp);
77
    GetTimeStamp(hBuff, &tstamp);
81
    return tstamp - audio_delta;
78
    return tstamp - audio_delta;
82
};
79
};
83
 
80
 
84
int decode_audio(AVCodecContext  *ctx, queue_t *qa)
81
int decode_audio(AVCodecContext  *ctx, queue_t *qa)
85
{
82
{
86
    static struct SwrContext *swr_ctx;
83
    static struct SwrContext *swr_ctx;
87
    static int64_t src_layout;
84
    static int64_t src_layout;
88
    static int src_freq;
85
    static int src_freq;
89
    static int src_channels;
86
    static int src_channels;
90
    static enum AVSampleFormat src_fmt = -1;
87
    static enum AVSampleFormat src_fmt = -1;
91
    static AVFrame *aFrame;
88
    static AVFrame *aFrame;
92
 
89
 
93
    AVPacket   pkt;
90
    AVPacket   pkt;
94
    AVPacket    pkt_tmp;
91
    AVPacket    pkt_tmp;
95
    int64_t dec_channel_layout;
92
    int64_t dec_channel_layout;
96
    int len, len2;
93
    int len, len2;
97
    int got_frame;
94
    int got_frame;
98
    int data_size;
95
    int data_size;
99
 
96
 
100
    if( astream.count > 192000*2)
97
    if( astream.count > 192000*2)
101
        return -1;
98
        return -1;
102
 
99
 
103
    if( get_packet(qa, &pkt) == 0 )
100
    if( get_packet(qa, &pkt) == 0 )
104
        return 0;
101
        return 0;
105
 
102
 
106
    if (!aFrame)
103
    if (!aFrame)
107
    {
104
    {
108
        if (!(aFrame = av_frame_alloc()))
105
        if (!(aFrame = av_frame_alloc()))
109
            return -1;
106
            return -1;
110
    } else
107
    } else
111
        avcodec_get_frame_defaults(aFrame);
108
        avcodec_get_frame_defaults(aFrame);
112
 
109
 
113
    pkt_tmp = pkt;
110
    pkt_tmp = pkt;
114
 
111
 
115
    while(pkt_tmp.size > 0)
112
    while(pkt_tmp.size > 0)
116
    {
113
    {
117
        data_size = 192000;
114
        data_size = 192000;
118
 
115
 
119
        got_frame = 0;
116
        got_frame = 0;
120
        len = avcodec_decode_audio4(ctx, aFrame, &got_frame, &pkt_tmp);
117
        len = avcodec_decode_audio4(ctx, aFrame, &got_frame, &pkt_tmp);
121
 
118
 
122
        if(len >= 0 && got_frame)
119
        if(len >= 0 && got_frame)
123
        {
120
        {
124
            char *samples;
121
            char *samples;
125
            int ch, plane_size;
122
            int ch, plane_size;
126
            int planar    = av_sample_fmt_is_planar(ctx->sample_fmt);
123
            int planar    = av_sample_fmt_is_planar(ctx->sample_fmt);
127
            int data_size = av_samples_get_buffer_size(&plane_size, ctx->channels,
124
            int data_size = av_samples_get_buffer_size(&plane_size, ctx->channels,
128
                                                   aFrame->nb_samples,
125
                                                   aFrame->nb_samples,
129
                                                   ctx->sample_fmt, 1);
126
                                                   ctx->sample_fmt, 1);
130
 
127
            pkt_tmp.data += len;
131
//            if(audio_base == -1.0)
-
 
132
//            {
-
 
133
//                if (pkt.pts != AV_NOPTS_VALUE)
-
 
134
//                    audio_base = get_audio_base() * pkt.pts;
-
 
135
//                printf("audio base %f\n", audio_base);
-
 
136
//            };
-
 
137
 
-
 
138
            pkt_tmp.data += len;
-
 
139
            pkt_tmp.size -= len;
128
            pkt_tmp.size -= len;
140
 
129
 
141
            dec_channel_layout =
130
            dec_channel_layout =
142
                (aFrame->channel_layout && aFrame->channels == av_get_channel_layout_nb_channels(aFrame->channel_layout)) ?
131
                (aFrame->channel_layout && aFrame->channels == av_get_channel_layout_nb_channels(aFrame->channel_layout)) ?
143
                aFrame->channel_layout : av_get_default_channel_layout(aFrame->channels);
132
                aFrame->channel_layout : av_get_default_channel_layout(aFrame->channels);
144
 
133
 
145
            if (aFrame->format          != src_fmt     ||
134
            if (aFrame->format          != src_fmt     ||
146
                dec_channel_layout      != src_layout  ||
135
                dec_channel_layout      != src_layout  ||
147
                aFrame->sample_rate     != src_freq    ||
136
                aFrame->sample_rate     != src_freq    ||
148
                !swr_ctx)
137
                !swr_ctx)
149
            {
138
            {
150
                swr_free(&swr_ctx);
139
                swr_free(&swr_ctx);
151
                swr_ctx = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16,
140
                swr_ctx = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16,
152
                                             aFrame->sample_rate, dec_channel_layout,aFrame->format,
141
                                             aFrame->sample_rate, dec_channel_layout,aFrame->format,
153
                                             aFrame->sample_rate, 0, NULL);
142
                                             aFrame->sample_rate, 0, NULL);
154
                if (!swr_ctx || swr_init(swr_ctx) < 0)
143
                if (!swr_ctx || swr_init(swr_ctx) < 0)
155
                {
144
                {
156
                    printf("Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
145
                    printf("Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
157
                        aFrame->sample_rate,   av_get_sample_fmt_name(aFrame->format), (int)aFrame->channels,
146
                        aFrame->sample_rate,   av_get_sample_fmt_name(aFrame->format), (int)aFrame->channels,
158
                        aFrame->sample_rate, av_get_sample_fmt_name(AV_SAMPLE_FMT_S16), 2);
147
                        aFrame->sample_rate, av_get_sample_fmt_name(AV_SAMPLE_FMT_S16), 2);
159
                    break;
148
                    break;
160
                }
149
                }
161
 
150
 
162
                src_layout   = dec_channel_layout;
151
                src_layout   = dec_channel_layout;
163
                src_channels = aFrame->channels;
152
                src_channels = aFrame->channels;
164
                src_freq     = aFrame->sample_rate;
153
                src_freq     = aFrame->sample_rate;
165
                src_fmt      = aFrame->format;
154
                src_fmt      = aFrame->format;
166
            };
155
            };
167
 
156
 
168
            if (swr_ctx)
157
            if (swr_ctx)
169
            {
158
            {
170
                const uint8_t **in = (const uint8_t **)aFrame->extended_data;
159
                const uint8_t **in = (const uint8_t **)aFrame->extended_data;
171
                uint8_t *out[] = {decoder_buffer};
160
                uint8_t *out[] = {decoder_buffer};
172
                int out_count = 192000 * 3 / 2 / av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
161
                int out_count = 192000 * 3 / 2 / av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
173
                len2 = swr_convert(swr_ctx, out, out_count, in, aFrame->nb_samples);
162
                len2 = swr_convert(swr_ctx, out, out_count, in, aFrame->nb_samples);
174
                if (len2 < 0) {
163
                if (len2 < 0) {
175
                    printf("swr_convert() failed\n");
164
                    printf("swr_convert() failed\n");
176
                    break;
165
                    break;
177
                }
166
                }
178
                if (len2 == out_count) {
167
                if (len2 == out_count) {
179
                    printf("warning: audio buffer is probably too small\n");
168
                    printf("warning: audio buffer is probably too small\n");
180
                    swr_init(swr_ctx);
169
                    swr_init(swr_ctx);
181
                }
170
                }
182
                data_size = len2 * 2 * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
171
                data_size = len2 * 2 * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
183
 
172
 
184
                mutex_lock(&astream.lock);
173
                mutex_lock(&astream.lock);
185
 
174
 
186
                samples = astream.buffer+astream.count;
175
                samples = astream.buffer+astream.count;
187
 
176
 
188
                memcpy(samples, decoder_buffer, data_size);
177
                memcpy(samples, decoder_buffer, data_size);
189
 
178
 
190
                astream.count += data_size;
179
                astream.count += data_size;
191
                mutex_unlock(&astream.lock);
180
                mutex_unlock(&astream.lock);
192
            };
181
            };
193
       }
182
       }
194
       else pkt_tmp.size = 0;
183
       else pkt_tmp.size = 0;
195
    }
184
    }
196
    av_free_packet(&pkt);
185
    av_free_packet(&pkt);
197
    return 1;
186
    return 1;
198
};
187
};
199
 
188
 
200
 
189
 
201
static void sync_audio(SNDBUF hbuff, int buffsize)
190
static void sync_audio(SNDBUF hbuff, int buffsize)
202
{
191
{
203
    SND_EVENT   evnt;
192
    SND_EVENT   evnt;
204
    uint32_t    offset;
193
    uint32_t    offset;
205
    double      time_stamp;
194
    double      time_stamp;
206
 
195
 
207
#ifdef BLACK_MAGIC_SOUND
196
#ifdef BLACK_MAGIC_SOUND
208
 
197
 
209
    while( player_state != CLOSED)
198
    while( player_state != CLOSED)
210
    {
199
    {
211
        GetNotify(&evnt);
200
        GetNotify(&evnt);
212
 
201
 
213
        if(evnt.code != 0xFF000001)
202
        if(evnt.code != 0xFF000001)
214
        {
203
        {
215
            printf("invalid event code %d\n\r", evnt.code);
204
            printf("invalid event code %d\n\r", evnt.code);
216
            continue;
205
            continue;
217
        }
206
        }
218
 
207
 
219
        if(evnt.stream != hbuff)
208
        if(evnt.stream != hbuff)
220
        {
209
        {
221
            printf("invalid stream %x hBuff= %x\n\r",
210
            printf("invalid stream %x hBuff= %x\n\r",
222
                    evnt.stream, hbuff);
211
                    evnt.stream, hbuff);
223
            continue;
212
            continue;
224
        }
213
        }
225
 
214
 
226
        GetTimeStamp(hbuff, &time_stamp);
215
        GetTimeStamp(hbuff, &time_stamp);
227
        audio_delta = time_stamp - last_time_stamp;
216
        audio_delta = time_stamp - last_time_stamp;
228
 
217
 
229
        offset = evnt.offset;
218
        offset = evnt.offset;
230
 
219
 
231
        mutex_lock(&astream.lock);
220
        mutex_lock(&astream.lock);
232
        {
221
        {
233
            if(astream.count < buffsize)
222
            if(astream.count < buffsize)
234
            {
223
            {
235
                memset(astream.buffer+astream.count,
224
                memset(astream.buffer+astream.count,
236
                       0, buffsize-astream.count);
225
                       0, buffsize-astream.count);
237
                astream.count = buffsize;
226
                astream.count = buffsize;
238
            };
227
            };
239
 
228
 
240
            SetBuffer(hbuff, astream.buffer, offset, buffsize);
229
            SetBuffer(hbuff, astream.buffer, offset, buffsize);
241
            samples_written+= buffsize/4;
230
            samples_written+= buffsize/4;
242
 
231
 
243
            astream.count -= buffsize;
232
            astream.count -= buffsize;
244
            if(astream.count)
233
            if(astream.count)
245
                memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
234
                memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
246
            mutex_unlock(&astream.lock);
235
            mutex_unlock(&astream.lock);
247
        };
236
        };
248
        break;
237
        break;
249
    };
238
    };
250
#endif
239
#endif
251
 
240
 
252
};
241
};
253
 
242
 
254
int audio_thread(void *param)
243
int audio_thread(void *param)
255
{
244
{
256
    SND_EVENT evnt;
245
    vst_t *vst = param;
-
 
246
    SND_EVENT evnt;
257
 
247
 
258
    int       buffsize;
248
    int       buffsize;
259
    int      samples;
249
    int      samples;
260
    int       err;
250
    int       err;
261
    char     *errstr;
251
    char     *errstr;
262
    int       active;
252
    int       active;
263
 
253
 
264
    if((err = CreateBuffer(snd_format|PCM_RING,0, &hBuff)) != 0)
254
    if((err = CreateBuffer(snd_format|PCM_RING,0, &hBuff)) != 0)
265
    {
255
    {
266
        errstr = "Cannot create sound buffer\n\r";
256
        errstr = "Cannot create sound buffer\n\r";
267
        goto exit_whith_error;
257
        goto exit_whith_error;
268
    };
258
    };
269
 
259
 
270
    SetVolume(hBuff,-900,-900);
260
    SetVolume(hBuff,-900,-900);
271
 
261
 
272
    if((err = GetBufferSize(hBuff, &buffsize)) != 0)
262
    if((err = GetBufferSize(hBuff, &buffsize)) != 0)
273
    {
263
    {
274
        errstr = "Cannot get buffer size\n\r";
264
        errstr = "Cannot get buffer size\n\r";
275
        goto exit_whith_error;
265
        goto exit_whith_error;
276
    };
266
    };
277
 
267
 
278
    __sync_or_and_fetch(&threads_running,AUDIO_THREAD);
268
    __sync_or_and_fetch(&threads_running,AUDIO_THREAD);
279
 
269
 
280
    resampler_size = buffsize = buffsize/2;
270
    resampler_size = buffsize = buffsize/2;
281
 
271
 
282
    samples = buffsize/4;
272
    samples = buffsize/4;
283
 
273
 
284
    while( player_state != CLOSED)
274
    while( player_state != CLOSED)
285
    {
275
    {
286
        uint32_t  offset;
276
        uint32_t  offset;
287
        double    event_stamp, wait_stamp;
277
        double    event_stamp, wait_stamp;
288
        int       too_late = 0;
278
        int       too_late = 0;
289
 
279
 
290
        switch(sound_state)
280
        switch(sound_state)
291
        {
281
        {
292
            case PREPARE:
282
            case PREPARE:
293
 
283
 
294
                mutex_lock(&astream.lock);
284
                mutex_lock(&astream.lock);
295
                    if(astream.count < buffsize*2)
285
                    if(astream.count < buffsize*2)
296
                    {
286
                    {
297
                        memset(astream.buffer+astream.count,
287
                        memset(astream.buffer+astream.count,
298
                               0, buffsize*2-astream.count);
288
                               0, buffsize*2-astream.count);
299
                        astream.count = buffsize*2;
289
                        astream.count = buffsize*2;
300
                    };
290
                    };
301
 
291
 
302
                    SetBuffer(hBuff, astream.buffer, 0, buffsize*2);
292
                    SetBuffer(hBuff, astream.buffer, 0, buffsize*2);
303
                    astream.count -= buffsize*2;
293
                    astream.count -= buffsize*2;
304
                    if(astream.count)
294
                    if(astream.count)
305
                        memcpy(astream.buffer, astream.buffer+buffsize*2, astream.count);
295
                        memcpy(astream.buffer, astream.buffer+buffsize*2, astream.count);
306
                mutex_unlock(&astream.lock);
296
                mutex_unlock(&astream.lock);
307
 
297
 
308
                SetTimeBase(hBuff, audio_base);
298
                SetTimeBase(hBuff, vst->audio_timer_base);
309
 
299
 
310
            case PAUSE_2_PLAY:
300
            case PAUSE_2_PLAY:
311
                GetTimeStamp(hBuff, &last_time_stamp);
301
                GetTimeStamp(hBuff, &last_time_stamp);
312
//                printf("last audio time stamp %f\n", last_time_stamp);
302
 
313
 
-
 
314
                if((err = PlayBuffer(hBuff, 0)) !=0 )
303
                if((err = PlayBuffer(hBuff, 0)) !=0 )
315
                {
304
                {
316
                    errstr = "Cannot play buffer\n\r";
305
                    errstr = "Cannot play buffer\n\r";
317
                    goto exit_whith_error;
306
                    goto exit_whith_error;
318
                };
307
                };
319
                active = 1;
308
                active = 1;
320
                sync_audio(hBuff, buffsize);
309
                sync_audio(hBuff, buffsize);
321
                sound_state = PLAY;
310
                sound_state = PLAY;
322
//                printf("render: set audio latency to %f\n", audio_delta);
311
 
323
 
-
 
324
                /* breaktrough */
312
                /* breaktrough */
325
 
313
 
326
            case PLAY:
314
            case PLAY:
327
                GetNotify(&evnt);
315
                GetNotify(&evnt);
328
 
316
 
329
                if(evnt.code != 0xFF000001)
317
                if(evnt.code != 0xFF000001)
330
                {
318
                {
331
                    printf("invalid event code %d\n\r", evnt.code);
319
                    printf("invalid event code %d\n\r", evnt.code);
332
                    continue;
320
                    continue;
333
                }
321
                }
334
 
322
 
335
                if(evnt.stream != hBuff)
323
                if(evnt.stream != hBuff)
336
                {
324
                {
337
                    printf("invalid stream %x hBuff= %x\n\r",
325
                    printf("invalid stream %x hBuff= %x\n\r",
338
                            evnt.stream, hBuff);
326
                            evnt.stream, hBuff);
339
                    continue;
327
                    continue;
340
                };
328
                };
341
 
329
 
342
                offset = evnt.offset;
330
                offset = evnt.offset;
343
 
331
 
344
                mutex_lock(&astream.lock);
332
                mutex_lock(&astream.lock);
345
                if(astream.count < buffsize)
333
                if(astream.count < buffsize)
346
                {
334
                {
347
                    memset(astream.buffer+astream.count,
335
                    memset(astream.buffer+astream.count,
348
                           0, buffsize-astream.count);
336
                           0, buffsize-astream.count);
349
                    astream.count = buffsize;
337
                    astream.count = buffsize;
350
                };
338
                };
351
 
339
 
352
                SetBuffer(hBuff, astream.buffer, offset, buffsize);
340
                SetBuffer(hBuff, astream.buffer, offset, buffsize);
353
 
341
 
354
                {
342
                {
355
                    double  val = 0;
343
                    double  val = 0;
356
                    int16_t *src = (int16_t*)astream.buffer;
344
                    int16_t *src = (int16_t*)astream.buffer;
357
                    int samples = buffsize/2;
345
                    int samples = buffsize/2;
358
                    int i;
346
                    int i;
359
 
347
 
360
                    for(i = 0, val = 0; i < samples/2; i++, src++)
348
                    for(i = 0, val = 0; i < samples/2; i++, src++)
361
                        if(val < abs(*src))
349
                        if(val < abs(*src))
362
                            val= abs(*src); // * *src;
350
                            val= abs(*src); // * *src;
363
 
351
 
364
                    sound_level_0 = val; //sqrt(val / (samples/2));
352
                    sound_level_0 = val; //sqrt(val / (samples/2));
365
 
353
 
366
                    for(i = 0, val = 0; i < samples/2; i++, src++)
354
                    for(i = 0, val = 0; i < samples/2; i++, src++)
367
                        if(val < abs(*src))
355
                        if(val < abs(*src))
368
                            val= abs(*src); // * *src;
356
                            val= abs(*src); // * *src;
369
 
357
 
370
                    sound_level_1 = val; //sqrt(val / (samples/2));
358
                    sound_level_1 = val; //sqrt(val / (samples/2));
371
 
359
 
372
 //                   printf("%d\n", sound_level);
360
 //                   printf("%d\n", sound_level);
373
                };
361
                };
374
 
362
 
375
                samples_written+= buffsize/4;
363
                samples_written+= buffsize/4;
376
 
364
 
377
                astream.count -= buffsize;
365
                astream.count -= buffsize;
378
                if(astream.count)
366
                if(astream.count)
379
                    memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
367
                    memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
380
                mutex_unlock(&astream.lock);
368
                mutex_unlock(&astream.lock);
381
                break;
369
                break;
382
 
370
 
383
            case PLAY_2_STOP:
371
            case PLAY_2_STOP:
384
                if( active )
372
                if( active )
385
                {
373
                {
386
                    ResetBuffer(hBuff, SND_RESET_ALL);
374
                    ResetBuffer(hBuff, SND_RESET_ALL);
387
                    audio_base = -1.0;
375
                	vst->audio_timer_valid = 0;
388
                    active = 0;
376
                    active = 0;
389
                }
377
                }
390
                sound_state = STOP;
378
                sound_state = STOP;
391
                break;
379
                break;
392
 
380
 
393
            case PLAY_2_PAUSE:
381
            case PLAY_2_PAUSE:
394
                if( active )
382
                if( active )
395
                {
383
                {
396
                    StopBuffer(hBuff);
384
                    StopBuffer(hBuff);
397
                };
385
                };
398
                sound_state = PAUSE;
386
                sound_state = PAUSE;
399
 
387
 
400
            case PAUSE:
388
            case PAUSE:
401
            case STOP:
389
            case STOP:
402
                delay(1);
390
                delay(1);
403
        };
391
        };
404
    }
392
    }
405
 
393
 
406
    __sync_and_and_fetch(&threads_running,~AUDIO_THREAD);
394
    __sync_and_and_fetch(&threads_running,~AUDIO_THREAD);
407
 
395
 
408
    StopBuffer(hBuff);
396
    StopBuffer(hBuff);
409
    DestroyBuffer(hBuff);
397
    DestroyBuffer(hBuff);
410
 
398
 
411
    return 0;
399
    return 0;
412
 
400
 
413
exit_whith_error:
401
exit_whith_error:
414
 
402
 
415
    printf(errstr);
403
    printf(errstr);
416
    return -1;
404
    return -1;
417
 
405
 
418
};
406
};