From: hackbard Date: Sun, 6 Jul 2003 12:01:06 +0000 (+0000) Subject: initial checkin X-Git-Url: https://hackdaworld.org/gitweb/?p=sound-tools%2Fhdrec.git;a=commitdiff_plain;h=1c9ee7257e9ea793b679b34fa4b1d6426042e974 initial checkin --- 1c9ee7257e9ea793b679b34fa4b1d6426042e974 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6bd5fd0 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +# Makefile of hdrec + +CFLAGS = -O3 -Wall +CC = gcc + +TARGETS = hdrec + +all: $(TARGETS) + +hdrec: + $(CC) $(CFLAGS) -Wall oss_api.c hdrec.c -o hdrec + +clean: + rm $(OBJS) hdrec + +remake: clean all diff --git a/hdrec b/hdrec new file mode 100755 index 0000000..41a6b8c Binary files /dev/null and b/hdrec differ diff --git a/hdrec.c b/hdrec.c new file mode 100644 index 0000000..ac6348e --- /dev/null +++ b/hdrec.c @@ -0,0 +1,158 @@ +/* + * hdrec -- some sort of multi tracker (not right now, but in the future :p) + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "oss_api.h" +#include "hdrec.h" + +int usage(void) { + printf("usage:\n\n"); + printf("-h \t\t print this help\n"); + printf("-r \t record to \n"); + printf("-p \t play from \n"); + printf("-s \t\t stereo\n"); + printf("-m \t\t mono\n"); + printf("-f \t 1=8bit - 2=16bit (le)\n"); + printf("-F \t frequency\n"); + + return 1; +} + +int main(int argc,char **argv) { + int sfile_fd; + int pfile_fd; + int audio_fd; + char device[MAX_C_DEVICE]; + int i,j,k; + int rw; + unsigned char mode=0; + int o_mode=0; + char record_file[MAX_C_FILE]; + char play_file[MAX_C_FILE]; + dsp_set set; + unsigned char *buf; + + /* defaults */ + strcpy(device,""); + set.format=AFMT_S16_LE; + set.freq=44100; + set.channel=STEREO; + + /* read argv */ + for(i=1;i +#include +#include +#include +#include +#include +#include +#include + +#include "oss_api.h" + +int get_dsp_cap(int fd,dsp_set *set,unsigned char print) { + if(ioctl(fd,SNDCTL_DSP_GETCAPS,&(set->cap))==-1) { + perror("SNDCTL_DSP_GETCAPS"); + return -1; + } + + if(print) { + printf("device capabilities:\n\n"); + printf("revision: %x\n",set->cap&DSP_CAP_REVISION); + printf("full duplex:\t%c\n",set->cap&DSP_CAP_DUPLEX?'y':'n'); + printf("real time:\t%c\n",set->cap&DSP_CAP_REALTIME?'y':'n'); + printf("int. buf:\t%c\n",set->cap&DSP_CAP_BATCH?'y':'n'); + printf("coprociessor:\t%c\n",set->cap&DSP_CAP_COPROC?'y':'n'); + printf("trigger:\t%c\n",set->cap&DSP_CAP_TRIGGER?'y':'n'); + printf("support mmap:\t%c\n",set->cap&DSP_CAP_MMAP?'y':'n'); + printf("multiple open:\t%c\n",set->cap&DSP_CAP_MULTI?'y':'n'); + printf("chan binding:\t%c\n",set->cap&DSP_CAP_BIND?'y':'n'); + } + + return 1; +} + +int set_dsp(int fd,dsp_set *set) { + int tmp; + + tmp=set->format; + if(ioctl(fd,SNDCTL_DSP_SETFMT,&(set->format))==-1) { + perror("SNDCTL_DSP_SETFMT"); + return -1; + } + if(set->format!=tmp) { + printf("format (%d) not supported!\n",tmp); + return -1; + } + tmp=set->channel; + if(ioctl(fd,SNDCTL_DSP_CHANNELS,&(set->channel))==-1) { + perror("SNDCTL_DSP_CHANNELS"); + return -1; + } + if(set->channel!=tmp) { + printf("%d-channel use not supported!\n",tmp); + return -1; + } + tmp=set->freq; + if(ioctl(fd,SNDCTL_DSP_SPEED,&(set->freq))==-1) { + perror("SNDCTL_DSP_SPEED"); + return -1; + } + if(set->freq!=tmp) { + printf("%d hz not suported!\n",tmp); + return -1; + } + if(ioctl(fd,SNDCTL_DSP_GETBLKSIZE,&(set->bufsize))==-1) { + perror("SOUNDCTL_DSP_GETBLKSIZE"); + return -1; + } + printf("\n\nSOUNDCTL_DSP_GETBLKSIZE = %d\n\n",set->bufsize); + + return 1; +} + +int open_sound_dev(char *dev,int mode) { + int fd; + + if((fd=open(dev,mode))==-1) { + perror("open"); + return -1; + } + + return fd; +} + +int open_file(char *file,int mode) { + int fd; + + if(mode) { + if((fd=open(file,mode,S_IRWXU))==-1) { + perror("open"); + return -1; + } + } else { + if((fd=open(file,mode))==-1) { + perror("open"); + return -1; + } + } + + return fd; +} + +int close_it(int fd) { + if(close(fd)==-1) { + perror("close"); + return -1; + } + + return 1; +} + diff --git a/oss_api.h b/oss_api.h new file mode 100644 index 0000000..67dbe65 --- /dev/null +++ b/oss_api.h @@ -0,0 +1,27 @@ +/* oss_api.h */ + +#ifndef OSS_API_H +#define OSS_API_H + +/* defines */ +#define MONO 1 +#define STEREO 2 +#define SAMPLES 100000 + +/* variables */ +typedef struct __dsp_set { + int cap; + int format; + int channel; + int freq; + int bufsize; +} dsp_set; + +/* function prototypes */ +int get_dsp_cap(int fd,dsp_set *set,unsigned char print); +int set_dsp(int fd,dsp_set *dsp_set); +int open_sound_dev(char *dev,int mode); +int open_file(char *file,int mode); +int close_it(int fd); + +#endif /* OSS_API_H */ diff --git a/oss_api.o b/oss_api.o new file mode 100644 index 0000000..5065496 Binary files /dev/null and b/oss_api.o differ