| 1 |
#include <stdio.h> |
|---|
| 2 |
#include <stdlib.h> |
|---|
| 3 |
#include <unistd.h> |
|---|
| 4 |
#include <fcntl.h> |
|---|
| 5 |
#include <sys/ioctl.h> |
|---|
| 6 |
#include <sys/soundcard.h> |
|---|
| 7 |
#include <math.h> |
|---|
| 8 |
|
|---|
| 9 |
#include "syre.h" |
|---|
| 10 |
|
|---|
| 11 |
int dev_dsp; |
|---|
| 12 |
|
|---|
| 13 |
void open_dev_dsp(void) |
|---|
| 14 |
{ |
|---|
| 15 |
|
|---|
| 16 |
int frequency, stereo, samplesize; |
|---|
| 17 |
|
|---|
| 18 |
int numfrags, fragsize, fragmentsize; |
|---|
| 19 |
|
|---|
| 20 |
if(!(dev_dsp = open("/dev/dsp", O_WRONLY | O_NDELAY, 0))) { |
|---|
| 21 |
|
|---|
| 22 |
fprintf(stdout, "Unable to open /dev/dsp\n"); |
|---|
| 23 |
exit(1); |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
samplesize = PLAYBACK_BITRATE; |
|---|
| 28 |
if( ioctl( dev_dsp, SNDCTL_DSP_SAMPLESIZE, &samplesize ) == -1 ) { |
|---|
| 29 |
|
|---|
| 30 |
fprintf( stderr, "Unable to set sample size!\n"); |
|---|
| 31 |
exit(1); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
stereo = 1; |
|---|
| 36 |
if( ioctl( dev_dsp, SNDCTL_DSP_STEREO, &stereo ) == -1 ) { |
|---|
| 37 |
|
|---|
| 38 |
fprintf( stderr, "Unable to set stereo playback!\n"); |
|---|
| 39 |
exit(1); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
frequency = PLAYBACK_FREQ; |
|---|
| 44 |
if( ioctl( dev_dsp, SNDCTL_DSP_SPEED, &frequency ) == -1 ) { |
|---|
| 45 |
|
|---|
| 46 |
fprintf( stderr, "Unable to set playback frequency!\n"); |
|---|
| 47 |
exit(1); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
numfrags = 64; |
|---|
| 52 |
fragsize = 17; |
|---|
| 53 |
|
|---|
| 54 |
fragmentsize = (numfrags << 16) | fragsize; |
|---|
| 55 |
if( ioctl( dev_dsp, SNDCTL_DSP_SETFRAGMENT, &fragmentsize) == -1) { |
|---|
| 56 |
|
|---|
| 57 |
fprintf( stderr, "Unable to set buffer fragment!\n"); |
|---|
| 58 |
exit(1); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
/* |
|---|
| 64 |
* if( ioctl( dev_dsp, SNDCTL_DSP_SYNC, 0 ) == -1 ) { |
|---|
| 65 |
|
|---|
| 66 |
fprintf( stderr, "Unable to sync dma!\n"); |
|---|
| 67 |
exit(1); |
|---|
| 68 |
} |
|---|
| 69 |
* |
|---|
| 70 |
* */ |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
void close_dev_dsp(void) |
|---|
| 77 |
{ |
|---|
| 78 |
|
|---|
| 79 |
close(dev_dsp); |
|---|
| 80 |
} |
|---|