• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
newbie low-level (HAL?) audio recording sample revisited
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

newbie low-level (HAL?) audio recording sample revisited


  • Subject: newbie low-level (HAL?) audio recording sample revisited
  • From: Akos Maroy <email@hidden>
  • Date: Tue, 24 Feb 2004 07:09:00 +0100
  • Organization: Tyrell Corp.

Hi,

I'd like to rephrase my question I posted previously. I'm looking for a simple way to open an audio device, configure it and read from it on MacOS X. Basically I'm looking for a short code snippet that does just this. for example, on Solaris / OpenBSD / NetBSD, the following few lines of code does just this. I wouldn't expect this to be a lot more complicated on MacOS X either. can someone give me a hand?


---------8<----------snip here for record.c---------------------
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/audioio.h>

#define FILE_NAME "/dev/audio"
#define SAMPLE_RATE 22050
#define CHANNEL 2
#define BITS_PER_SAMPLE 16
#define BUF_SIZE 4

int main(int argc, char **argv) {
int fd;
audio_info_t audioInfo;
unsigned char buf[BUF_SIZE];
unsigned int len = BUF_SIZE;
ssize_t ret;

fd = open( FILE_NAME, O_RDONLY);

AUDIO_INITINFO( &audioInfo);
audioInfo.record.sample_rate = SAMPLE_RATE;
audioInfo.record.channels = CHANNEL;
audioInfo.record.precision = BITS_PER_SAMPLE;
audioInfo.record.encoding = AUDIO_ENCODING_LINEAR;

if ( ioctl(fd, AUDIO_SETINFO, &audioInfo) ) {
printf("can't set audio info, error: %d\n", errno);
}

ret = read(fd, buf, len);

printf("%d returned by read\n", ret);
if ( ret == -1 ) {
printf("error code %d\n", errno);
}

close(fd);

return 0;
}
--------->8----------snip here for record.c---------------------
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Audiounits: For the love of Xcode!!
      • From: email@hidden
  • Prev by Date: Re: Is there any clock drift compensation mechanism in the HAL?
  • Next by Date: Re: Audiounits: For the love of Xcode!!
  • Previous by thread: Audiounits: For the love of Xcode!!
  • Next by thread: Re: Audiounits: For the love of Xcode!!
  • Index(es):
    • Date
    • Thread