Subject: Re: [linux-audio-dev] Another Annoying "How Do I Get Started" Question
From: reine_AT_music-corner.org
Date: Sat Jul 07 2001 - 23:29:21 EEST
Here are three functions that i use in my
little mixbas program. It's very basic
only for output probably not very clever
but it worked on my mashiine last time i
trided.
The whole program can be found at
http://www.music-corner.org/sound.html
int InitDspOut(void)
{
long blocksize,svar;
long channelMode=1; //stereo=1 mono=0
long dsp_speed=SAMPLERATE;
long soundFormat=AFMT_S16_LE;
int sound=open("/dev/dsp",O_WRONLY);
if (sound==-1) {
fprintf(stderr,"Could not open /dev/dsp\n");
}
svar=(2<<16)|(14);
svar=ioctl(sound,SNDCTL_DSP_SETFRAGMENT,&svar);
if (svar<0) printf("Error in SNDCTL_DSP_SETFRAGMENT.\n");
svar=ioctl(sound,SNDCTL_DSP_SETFMT,&soundFormat);
if (svar<0) printf("Error in .\n");
svar=ioctl(sound,SNDCTL_DSP_STEREO,&channelMode);
if (svar<0) printf("Error in DSP_STEREO.\n");
svar=ioctl(sound,SNDCTL_DSP_SPEED,&dsp_speed);
if (svar<0) printf("Error in DSP_SPEED.\n");
// else printf("Sample rate %d.\n",dsp_speed);
svar=ioctl(sound,SNDCTL_DSP_GETBLKSIZE,&blocksize);
if (svar<0) printf("Error in DSP_GETBLKSIZE.\n");
if (blocksize!=BLOCKSIZE) {
printf("Warning! BLOCKSIZE=%d but blocksize=%d.\n",BLOCKSIZE,blocksize);
}
// Show_audio_buff_info(sound);
return(sound);
}
void FreeDspOut(int fh)
{
short *silence=AllocateShort(BLOCKSAMPLES);
write(fh,silence,BLOCKSIZE);
free(silence);
close(fh);
}
void Show_audio_buff_info(int fh)
{
audio_buf_info info;
ioctl(fh, SNDCTL_DSP_GETOSPACE, &info);
printf("%d %d %d %d\n",info.fragments,info.fragstotal,
info.fragsize,info.bytes);
}
// End of DspOut functions
Reine
New emailaddress: reine_AT_music-corner.org
New URL to webpage: http://www.music-corner.org
This archive was generated by hypermail 2b28 : Sat Jul 07 2001 - 17:18:14 EEST