솔직히 버그가 좀 있습니다.
일부러 버그 못잡은게 아니고 몰라서 못잡고 있습니다.
| 코드: |
|
/* Copyright (c) 2002 Information Equipment co.,LTD. All Right Reserved. Code by JaeHyuk Cho <minzkn@infoeq.co.kr> - Little endian base - Simple is best */ #if !defined(DEF_wave_c) #define DEF_wave_c "wave.c" #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/ioctl.h> #include <fcntl.h> #include <string.h> #include <linux/soundcard.h> /* Little endian */ #define DEF_WAVE_MAGIC(a,b,c,d) ( (a) | (b << 8) | (c << 16) | (d << 24) ) typedef struct { unsigned long Magic; /* "RIFF" */ unsigned long Length; /* File length */ unsigned long Type; /* "WAVE" */ }t_WAVE_Header; typedef struct { unsigned short Format; unsigned short Channels; /* 1 = Mono, 2 = Stereo */ unsigned long Frequency; /* Frequency of sample */ unsigned long BytesPerSecond; /* Bytes per second */ unsigned short BytesPerSample; /* Bytes per sample */ unsigned short BitsPerSample; /* Bits per sample */ }t_WAVE_FMT; typedef struct { unsigned long Magic; /* "data" */ unsigned long Length; /* Sample count */ }t_WAVE_Chunk; int main(int s_Argc, char **s_Argv); int MZ_WAVE_Play(int s_Handle); int main(int s_Argc, char **s_Argv) { fprintf(stdout, "MZWAVE Release 0.0.1 - Copyright (c) Information Equipment co.,LTD. - %s %s\n", __DATE__, __TIME__); fprintf(stdout, "Code by JaeHyuk Cho , ApplicationName: MZ PCM player , Made in korea.\n\n"); if(s_Argc > 1) { int s_Handle; s_Handle = open(s_Argv[1], O_RDONLY); if(s_Handle >= 0) { MZ_WAVE_Play(s_Handle); close(s_Handle); } else fprintf(stderr, "Can not open \"%s\"\n", s_Argv[1]); } else fprintf(stderr, "Usage: %s <wave file>\n", s_Argv[0]); fprintf(stdout, "\nEnd of %s\n", s_Argv[0]); return(0); } int MZ_WAVE_Play(int s_Handle) { int s_Return = (-1); int s_ReadSize, s_DSP, s_DSP_Format, s_DSP_Channels; t_WAVE_Header s_WAVE_Header; t_WAVE_FMT s_WAVE_FMT; t_WAVE_Chunk s_WAVE_Chunk; s_ReadSize = read(s_Handle, (void *)&s_WAVE_Header, sizeof(s_WAVE_Header)); if(s_ReadSize == sizeof(s_WAVE_Header)) { if(s_WAVE_Header.Magic == DEF_WAVE_MAGIC('R', 'I', 'F', 'F')) { fprintf(stdout, "INFO: File length = %lu\n", s_WAVE_Header.Length); switch(s_WAVE_Header.Type) { case DEF_WAVE_MAGIC('W', 'A', 'V', 'E'): s_ReadSize = read(s_Handle, (void *)&s_WAVE_Chunk, sizeof(s_WAVE_Chunk)); if(s_ReadSize == sizeof(s_WAVE_Chunk)) { if(s_WAVE_Chunk.Magic == DEF_WAVE_MAGIC('f', 'm', 't', ' ')) { fprintf(stdout, "INFO: Chunk length = %lu\n", s_WAVE_Chunk.Length); s_ReadSize = read(s_Handle, (void *)&s_WAVE_FMT, sizeof(s_WAVE_FMT)); if(s_ReadSize == sizeof(s_WAVE_FMT)) { fprintf(stdout, "INFO: Format = 0x%04x\n" , (unsigned int )s_WAVE_FMT.Format); fprintf(stdout, "INFO: Channels = %u\n" , (unsigned int )s_WAVE_FMT.Channels); fprintf(stdout, "INFO: Frequency = %lu\n" , (unsigned long)s_WAVE_FMT.Frequency); fprintf(stdout, "INFO: Bytes per second = %lu\n" , (unsigned long)s_WAVE_FMT.BytesPerSecond); fprintf(stdout, "INFO: Bytes per sample = %u\n" , (unsigned int )s_WAVE_FMT.BytesPerSample); fprintf(stdout, "INFO: Bits per sample = %u\n" , (unsigned int )s_WAVE_FMT.BitsPerSample); s_DSP = open("/dev/dsp", O_WRONLY); if(s_DSP < 0)s_DSP = open("/dev/audio", O_WRONLY); if(s_DSP >= 0) { if(s_WAVE_FMT.BytesPerSample == 1)s_DSP_Format = AFMT_S8; else s_DSP_Format = AFMT_S16_LE; s_DSP_Channels = s_WAVE_FMT.Channels; if(ioctl(s_DSP, SNDCTL_DSP_SETFMT, &s_DSP_Format) == 0) { if(ioctl(s_DSP, SNDCTL_DSP_CHANNELS, &s_DSP_Channels) == 0) { if(ioctl(s_DSP, SNDCTL_DSP_SPEED, &s_WAVE_FMT.Frequency) == 0) { unsigned char s_Buffer[32 << 10]; s_Return = 0; do { s_ReadSize = read(s_Handle, (void *)&s_Buffer[0], sizeof(s_Buffer)); if(s_ReadSize > 0) { s_Return += s_ReadSize; write(s_DSP, (void *)&s_Buffer[0], s_ReadSize); } }while(s_ReadSize > 0); } else fprintf(stderr, "Can not ioctl SNDCTL_DSP_SPEED !!!\n"); } else fprintf(stderr, "Can not ioctl SNDCTL_DSP_CHANNELS !!!\n"); } else fprintf(stderr, "Can not ioctl SNDCTL_DSP_SETFMT !!!\n"); close(s_DSP); } else fprintf(stderr, "Can not open DSP !!!\n"); } else fprintf(stderr, "Can not read s_WAVE_FMT !!!\n"); } else fprintf(stderr, "Invalid Magic #1\n"); } else fprintf(stderr, "Can not read s_WAVE_Chunk !!!\n"); break; default: fprintf(stderr, "Not support format !!!\n"); break; } } else fprintf(stderr, "Invalid Magic #0 !!!\n"); } else fprintf(stderr, "Can not read s_WAVE_Header !!!\n"); return(s_Return); } #endif /* End of source */ |



글
댓글을 달아 주세요
댓글 RSS 주소 : http://blog.minzkn.com/rss/comment/75댓글 ATOM 주소 : http://blog.minzkn.com/atom/comment/75