19,24 → 19,13 |
#include "../mpg/mpg123.h" |
#include "../sound.h" |
|
typedef struct |
{ |
int sender; |
int size; |
int code; |
char data[1]; |
} IPC; |
|
int ipc_client = 0; |
|
#define MP3_ERROR_OUT_OF_BUFFER 5 |
int m_last_error; |
|
void _stdcall thread_proc(void *param); |
void _stdcall create_thread(void *proc, void *param, int stack_size); |
void _stdcall init_ipc(void); |
void _stdcall send_ipc(int dst, DWORD code); |
IPC * _stdcall recieve_ipc(void); |
|
void touch(char *buf, int size); |
int mp3FindSync(byte* buf, int size, int* sync); |
47,16 → 36,9 |
struct reader rd; |
struct frame fr; |
|
void draw_window(); |
void draw_progress_bar(); |
void do_ipc(); |
void exit(); |
|
|
DWORD hDrv; |
DWORD hSound; |
SNDBUF hBuff; |
volatile int snd_init=0; |
|
CTRL_INFO info; |
|
68,7 → 50,6 |
int pan =0; |
|
DWORD status; |
DWORD offset; |
DWORD first_sync; |
|
unsigned char *testbuff; |
81,224 → 62,12 |
int outremain; |
int totalout; |
int done; |
char path[1024]; |
|
char header[] = "AC97 MP3 player"; |
char buttons_text[]=" Play Stop << >> Vol- Vol+"; |
|
void (*snd_play)(); |
|
|
int main(int argc, char *argv[]) //int argc, char *argv[]) |
{ |
int err; |
int ver; |
int evnt; |
int key; |
int pos; |
int msg; |
int cnt; |
IPC *incom; |
|
_asm |
{ |
mov eax, 40 |
mov ebx, 0x47 ;recieve ipc |
int 0x40 |
mov eax, 66 |
mov ebx, 1 |
mov ecx, 1 |
int 0x40 |
}; |
init_ipc(); |
InitHeap(0); |
|
if(err = InitSound(&ver)) |
{ debug_out_str("Sound service not installed\n\r"); |
return 0; |
} |
|
if( (SOUND_VERSION>(ver&0xFFFF)) || |
(SOUND_VERSION<(ver >> 16))) |
{ debug_out_str("Sound service version mismatch\n\r"); |
return 0; |
} |
|
make_decode_tables(32767); |
init_layer2(); |
init_layer3(32); |
fr.single = -1; |
|
outremain = 0x40000 ; |
if( !(outbuf=UserAlloc(outremain))) |
return 0; |
|
touch(outbuf, outremain); |
|
if ( !(testbuff=UserAlloc(4096))) |
return 0; |
|
if (! (inpbuf=UserAlloc(0x10000))) |
return 0; |
|
touch(inpbuf, 0x10000); |
create_reader(&rd, inpbuf, 0x10000); |
|
fname = argv[1]; |
|
if(get_fileinfo(fname, &fileinfo)==FILE_NOT_FOUND) |
{ |
_asm |
{ |
mov eax, 23 |
mov ebx, 100 |
int 0x40 |
mov [msg], eax |
} |
if (msg != 7) |
{ |
debug_out_str("\n\rfile not found\n\r"); |
return 0; |
}; |
incom = recieve_ipc(); |
if(incom->code != 'CNCT') |
{ |
debug_out_str("\n\rinvalid ipc code\n\r"); |
status = ST_EXIT; |
return 0; |
}; |
ipc_client = incom->sender; |
send_ipc(ipc_client,'CNCT'); |
}; |
|
|
snd_init=0; |
create_thread(thread_proc, 0, 4096); |
|
for(snd_init=0,cnt=100; (snd_init==0)&&(cnt!=0); cnt--) |
delay(10); |
|
if (!snd_init) |
return 0; |
|
draw_window(); |
|
while(1) |
{ if(status==ST_PLAY) |
{ draw_progress_bar(); |
evnt = wait_for_event(80); |
} |
else |
evnt = wait_for_event_infinite(); |
|
switch(evnt) |
{ |
case EV_REDRAW: |
draw_window(); |
break; |
|
case EV_KEY: |
if(!get_key(&key)) |
{ |
|
switch(key) |
{ case 0xE0: |
case 0xE1: |
break; |
default: |
switch (key) |
{ |
case 0x01: //Esc |
status = ST_EXIT; |
exit(); |
break; |
|
case 0x47: //Home |
if(l_vol < 0) |
{ l_vol+=100; |
r_vol+=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
case 0x4F: //End |
if(l_vol > -10000) |
{ l_vol-=100; |
r_vol-=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
case 0x53: |
if(pan > -10000) |
{ pan -=100; |
SetPan(hBuff,pan); |
}; |
break; |
case 0x51: |
if(pan < 10000) |
{ pan +=100; |
SetPan(hBuff,pan); |
}; |
break; |
} |
}; |
}; |
break; |
|
case EV_BUTTON: |
switch(get_button_id()) |
{ case 1: |
status = ST_EXIT; |
exit(); |
break; |
|
case 0x10: |
status = ST_PLAY; |
continue; |
|
case 0x11: |
status = ST_STOP; |
break; |
// case 0x12: |
// case 0x13: |
case 0x14: |
if(l_vol > -10000) |
{ |
l_vol-=100; |
r_vol-=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
|
case 0x15: |
if(l_vol < 0) |
{ l_vol+=100; |
r_vol+=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
|
case 0x30: |
if(status==ST_DONE) |
break; |
pos = (GetMousePos(REL_WINDOW)>>16)-7; |
offset = ((fileinfo.size-44)/286*pos+44)&0xFFFFFFFC; |
set_reader(&rd, offset); |
draw_progress_bar(); |
break; |
}; |
break; |
case EV_IPC: |
do_ipc(); |
break; |
}; |
}; |
|
|
|
|
return 0; |
}; |
|
|
void draw_window() |
{ |
BeginDraw(); |
343,7 → 112,108 |
} |
} |
|
int main(int argc, char *argv[]) //int argc, char *argv[]) |
{ |
DWORD fmt; |
DWORD r_bytes; |
int retval; |
int err; |
int ver; |
|
fname = argv[1]; |
debug_out_str("\n\rPlay file "); |
debug_out_str(fname); |
debug_out_str("\n\r"); |
|
InitHeap(1024*1024); |
if(get_fileinfo(fname, &fileinfo)==FILE_NOT_FOUND) |
{ debug_out_str("\n\rfile not found\n\r"); |
return 0; |
}; |
|
if(err = InitSound(&ver)) |
{ |
debug_out_str("Sound service not installed\n\r"); |
return 0; |
} |
|
if( (SOUND_VERSION>(ver&0xFFFF)) || |
(SOUND_VERSION<(ver >> 16))) |
{ |
debug_out_str("Sound service version mismatch\n\r"); |
return 0; |
} |
|
testbuff = UserAlloc(4096); |
|
get_fileinfo(fname, &fileinfo); |
r_bytes=0; |
retval=read_file (fname,testbuff,0,2048,&r_bytes); |
if ( retval && (r_bytes==0)) |
return 0; |
|
inpbuf = UserAlloc(0x10000); |
touch(inpbuf, 0x10000); |
|
create_reader(&rd, inpbuf, 0x10000); |
init_reader(&rd,fname); |
|
fmt = test_wav((WAVEHEADER*)testbuff); |
if (fmt != 0) |
{ |
snd_play = &play_wave; |
set_reader(&rd, 44); |
outbuf = UserAlloc(32*1024); |
touch(outbuf, 32768); |
} |
else |
{ fmt = test_mp3(testbuff); |
if(fmt ==0) return 0; |
snd_play = &play_mp3; |
|
outremain = 0x40000 ; |
outbuf = UserAlloc(outremain); |
touch(outbuf, outremain); |
make_decode_tables(32767); |
init_layer2(); |
init_layer3(32); |
fr.single = -1; |
}; |
|
status = ST_PLAY; |
|
if (err = CreateBuffer(fmt,0, &hBuff)) |
{ |
debug_out_str("create buffer return error\n\r"); |
; return 0; |
} |
|
SetVolume(hBuff,l_vol,r_vol); |
GetVolume(hBuff,&l_vol,&r_vol); |
|
create_thread(thread_proc, 0, 4096); |
|
while(1) |
{ delay(10); |
switch(status) |
{ case ST_PLAY: |
snd_play(); |
continue; |
|
case ST_STOP: |
StopBuffer(hBuff); |
status = ST_DONE; |
continue; |
|
case ST_EXIT: |
StopBuffer(hBuff); |
DestroyBuffer(hBuff); |
return 0; |
}; |
}; |
return 0; |
}; |
|
void touch(char *buf, int size) |
{ int i; |
char a; |
361,15 → 231,7 |
if(!rd.head_read(&rd,&hdr)) |
return 0; |
if(!decode_header(&fr,hdr)) |
{ |
if((hdr & 0xffffff00) == 0x49443300) |
{ |
int id3length = 0; |
id3length = parse_new_id3(&rd, hdr); |
continue; |
}; |
|
rd.strpos-=3; |
{ rd.strpos-=3; |
rd.stream-=3; |
rd.strremain+=3; |
continue; |
395,6 → 257,7 |
int totalout; |
int outcount; |
|
// memset(&fr,0,sizeof(fr)); |
fr.down_sample_sblimit = 32; |
fr.single = -1; |
reset_mpg(); |
431,14 → 294,18 |
totalout = 4096; |
}; |
} |
else if(totalout < 8192) continue; |
else |
if(totalout < 8192) |
continue; |
|
outPtr = outbuf; |
while (totalout >= 4096) |
{ |
|
WaveOut(hBuff,outPtr,4096); |
if(status!=ST_PLAY) |
{ StopBuffer(hBuff); |
{ if(status != ST_EXIT) |
status = ST_STOP; |
return; |
}; |
totalout-=4096; |
445,60 → 312,17 |
outPtr+=4096; |
outremain+=4096; |
}; |
|
if(done) |
{ status = ST_STOP; |
break; |
|
if( ipc_client) |
send_ipc(ipc_client,'DONE'); |
return; |
} |
memmove(outbuf,outPtr, totalout); |
outPtr = outbuf+totalout; |
}; |
}; |
|
|
int play_track(char *path) |
{ |
DWORD fmt; |
DWORD r_bytes; |
int retval; |
int err; |
// int err; |
|
retval = ST_DONE; |
|
get_fileinfo(path, &fileinfo); |
offset = 0; |
err=read_file (path,testbuff,0,2048,&r_bytes); |
if (err) |
return ST_DONE; |
|
init_reader(&rd,path); |
|
fmt = test_wav((WAVEHEADER*)testbuff); |
if (fmt != 0) |
{ |
snd_play = &play_wave; |
set_reader(&rd, 44); |
retval = ST_PLAY; |
} |
else |
{ fmt = test_mp3(testbuff); |
if(fmt ==0) |
return ST_DONE; |
|
snd_play = &play_mp3; |
outremain = 0x40000; |
retval = ST_PLAY; |
if(status != ST_EXIT) |
status = ST_STOP; |
}; |
|
SetFormat(hBuff, fmt); |
return retval; |
}; |
|
|
void play_wave() |
{ int retval; |
|
525,85 → 349,128 |
StopBuffer(hBuff); |
}; |
|
void do_ipc() |
void _stdcall thread_proc(void *param) |
{ int evnt; |
int pos; |
int key; |
DWORD offset; |
|
_asm |
{ |
IPC *incom; |
incom = recieve_ipc(); |
switch(incom->code) |
{ |
case 'PLAY': |
fname = incom->data; |
status = ST_TRACK; |
return; |
mov eax, 66 |
mov ebx, 1 |
mov ecx, 1 |
int 0x40 |
}; |
|
case 'STOP': |
status = ST_STOP; |
return; |
draw_window(); |
|
case 'EXIT': |
status = ST_EXIT; |
exit(); |
}; |
}; |
while(1) |
{ if(status==ST_PLAY) |
{ draw_progress_bar(); |
evnt = wait_for_event(80); |
} |
else |
evnt = wait_for_event_infinite(); |
|
void _stdcall thread_proc(void *param) |
switch(evnt) |
{ |
int err; |
case EV_REDRAW: |
draw_window(); |
break; |
|
if (err = CreateBuffer(PCM_ALL|PCM_OUT,0, &hBuff)) |
case EV_KEY: |
if(!get_key(&key)) |
{ |
debug_out_str("create buffer return error\n\r"); |
|
switch(key) |
{ case 0xE0: |
case 0xE1: |
break; |
default: |
switch (key) |
{ |
case 0x01: //Esc |
status = ST_EXIT; |
exit(); |
}; |
break; |
|
case 0x47: //Home |
if(l_vol < 0) |
{ l_vol+=100; |
r_vol+=100; |
SetVolume(hBuff,l_vol,r_vol); |
GetVolume(hBuff,&l_vol,&r_vol); |
// debug_out_hex(l_vol); |
// debug_out_str("\n\r"); |
// debug_out_hex(r_vol); |
// debug_out_str("\n\r"); |
}; |
break; |
case 0x4F: //End |
if(l_vol > -10000) |
{ l_vol-=100; |
r_vol-=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
case 0x53: |
if(pan > -10000) |
{ pan -=100; |
SetPan(hBuff,pan); |
}; |
break; |
case 0x51: |
if(pan < 10000) |
{ pan +=100; |
SetPan(hBuff,pan); |
}; |
break; |
} |
}; |
}; |
break; |
|
if(fname[0] !='/0') |
status = play_track(fname); |
case EV_BUTTON: |
switch(get_button_id()) |
{ case 1: |
status = ST_EXIT; |
exit(); |
break; |
|
debug_out_str("\n\rPlay file "); |
debug_out_str(fname); |
debug_out_str("\n\r"); |
case 0x10: |
status = ST_PLAY; |
continue; |
|
snd_init = 1; |
|
while(1) |
{ delay(10); |
switch(status) |
case 0x11: |
status = ST_STOP; |
break; |
// case 0x12: |
// case 0x13: |
case 0x14: |
if(l_vol > -10000) |
{ |
case ST_TRACK: |
strcpy(path, fname); |
status = play_track(fname); |
if( ipc_client & (status == ST_DONE)) |
{ send_ipc(ipc_client,'DONE'); |
continue; |
l_vol-=100; |
r_vol-=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
|
case ST_PLAY: |
snd_play(); |
continue; |
case 0x15: |
if(l_vol < 0) |
{ l_vol+=100; |
r_vol+=100; |
SetVolume(hBuff,l_vol,r_vol); |
}; |
break; |
|
case ST_STOP: |
StopBuffer(hBuff); |
status = ST_DONE; |
continue; |
|
case ST_EXIT: |
StopBuffer(hBuff); |
DestroyBuffer(hBuff); |
if (ipc_client) |
send_ipc(ipc_client,'EXIT'); |
return; |
case 0x30: |
if(status==ST_DONE) |
break; |
pos = (GetMousePos(REL_WINDOW)>>16)-7; |
offset = ((fileinfo.size-44)/286*pos+44)&0xFFFFFFFC; |
set_reader(&rd, offset); |
draw_progress_bar(); |
break; |
}; |
}; |
|
|
}; |
}; |
|
void delay (int val) |
{ |