Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1696 serge 1
 
2
#include 
3
#include 
4
#include 
5
6
 
7
#include 
8
#include "sound.h"
9
#include "fplay.h"
10
11
 
12
 
13
14
 
15
16
 
17
18
 
19
20
 
21
{
22
    uint32_t tmp;
23
24
 
25
"0:\n\t"
26
    "mov %0, %1\n\t"
27
    "testl %1, %1\n\t"
28
    "jz 1f\n\t"
29
30
 
31
    "movl $1,  %%ebx\n\t"
32
    "int  $0x40\n\t"
33
    "jmp 0b\n\t"
34
"1:\n\t"
35
    "incl %1\n\t"
36
    "xchgl %0, %1\n\t"
37
    "testl %1, %1\n\t"
38
	"jnz 0b\n"
39
    : "+m" (*val), "=&r"(tmp)
40
    ::"eax","ebx" );
41
}
42
43
 
44
int sample_rate;
45
46
 
47
{
48
    int    err;
49
    int    version =-1;
50
    char  *errstr;
51
52
 
53
    {
54
        errstr = "Sound service not installed\n\r";
55
        goto exit_whith_error;
56
    }
57
    printf("sound version 0x%x\n", version);
58
59
 
60
        (SOUND_VERSION<(version >> 16)))
61
    {
62
        errstr = "Sound service version mismatch\n\r";
63
        goto exit_whith_error;
64
    }
65
66
 
67
68
 
69
70
 
71
72
 
73
74
 
75
76
 
77
    return 0;
78
};
79
80
 
81
static double  audio_delta;
82
83
 
84
{
85
    double tstamp;
86
87
 
88
    return tstamp - audio_delta;
89
};
90
91
 
92
 
93
{
94
    SND_EVENT evnt;
95
    int       buffsize;
96
    int      samples;
97
    int       err;
98
    char     *errstr;
99
100
 
101
 
102
    {
103
        errstr = "Cannot create sound buffer\n\r";
104
        goto exit_whith_error;
105
    };
106
107
 
108
109
 
110
    {
111
        errstr = "Cannot get buffer size\n\r";
112
        goto exit_whith_error;
113
    };
114
115
 
116
117
 
118
119
 
120
               (status != 0) )
121
        yield();
122
123
 
124
    {
125
        SetBuffer(hBuff, astream.buffer, 0, buffsize);
126
        astream.count -= buffsize;
127
        if(astream.count)
128
            memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
129
        spinlock_unlock(&astream.lock);
130
    };
131
132
 
133
    {
134
        errstr = "Cannot play buffer\n\r";
135
        goto exit_whith_error;
136
    };
137
138
 
139
 
140
141
 
142
    {
143
        uint32_t  offset;
144
145
 
146
147
 
148
        {
149
            printf("invalid event code %d\n\r", evnt.code);
150
            continue;
151
        }
152
153
 
154
        {
155
            printf("invalid stream %x hBuff= %x\n\r",
156
                    evnt.stream, hBuff);
157
            continue;
158
        }
159
160
 
161
        samples_lost = audio_delta*sample_rate/1000;
162
163
 
164
165
 
166
        {
167
            SetBuffer(hBuff, astream.buffer, offset, buffsize);
168
            astream.count -= buffsize;
169
            if(astream.count)
170
                memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
171
            spinlock_unlock(&astream.lock);
172
        };
173
        break;
174
    };
175
#endif
176
177
 
178
179
 
180
    {
181
        uint32_t  offset;
182
        double    event_stamp, wait_stamp;
183
        int       too_late = 0;
184
185
 
186
187
 
188
        {
189
            printf("invalid event code %d\n\r", evnt.code);
190
            continue;
191
        }
192
193
 
194
        {
195
            printf("invalid stream %x hBuff= %x\n\r",
196
                    evnt.stream, hBuff);
197
            continue;
198
        };
199
200
 
201
202
 
203
204
 
205
               (status != 0) )
206
        {
207
            yield();
208
            GetTimeStamp(hBuff, &wait_stamp);
209
            if( (wait_stamp - event_stamp) >
210
                 samples*1500/sample_rate )
211
            {
212
                samples_lost+= samples;
213
                audio_delta = (double)samples_lost*1000/sample_rate;
214
//                printf("audio delta %f\n", audio_delta);
215
                too_late = 1;
216
                break;
217
            }
218
        };
219
220
 
221
            continue;
222
223
 
224
        SetBuffer(hBuff, astream.buffer, offset, buffsize);
225
        astream.count -= buffsize;
226
        if(astream.count)
227
            memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
228
        spinlock_unlock(&astream.lock);
229
    }
230
231
 
232
233
 
234
235
 
236
    return ;
237
238
 
239