Re: [linux-audio-dev] laptop sound

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] laptop sound
From: douglas irving repetto (douglas_AT_music.columbia.edu)
Date: Mon Nov 27 2000 - 22:10:03 EET


Paul Winkler wrote:

>
> The Diamond Sonic Impact based on this same chip was described as
> "near-CD quality in playback and near-telephone quality in recording".
> I think this is what I have in my laptop. Playback does sound pretty
> decent. Haven't tried recording yet.
>

speaking of bad-sounding laptops, the maestro 2e in my dell inspiron
7500 sounds really crappy with the passthru code below when i a/b a CD.
just playing the CD normally sounds fine, but i guess it must be using
another set of converters on the CD player itself. it's amazing how bad
one generation of d/a -> a/d -> d/a can sound! it's all noisey and buzzy
and sounds like it's being very subtly ring-modulated!

good thing this is my primary axe for live gigs...

douglas

/*

soundthru.c

*/

#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <sys/soundcard.h>

#define BUFFER_SIZE 1024
#define FORMAT AFMT_S16_LE
#define CHANNELS 1 // 0=mono 1=stereo
#define SAMPLE_RATE 44100

int soundthru()
{
        //file i/o
        short* in_ptr;
        short* in_data_start_ptr;
        int bytes_read = 0;
        int bytes_written = 0;
        int handle;
        int channels;
        int format;
        int sample_rate;
        int setting;
        short write_size;
        handle = -1;
        //format info
        channels = CHANNELS;
        format = FORMAT;
        sample_rate = SAMPLE_RATE;
        setting = 0x0003000C; // 3 fragments 4kb buffer
        //1024 * 2 channels * 2 bytes per sample
        write_size = BUFFER_SIZE * 2 * 2L;
        
        if ( (handle = open("/dev/dsp",O_RDWR)) == -1 ) {
                perror("open /dev/dsp");
                return -1;
        }
        
        if ( ioctl(handle, SNDCTL_DSP_SETFRAGMENT, &setting) == -1 ) {
                perror("ioctl set fragment");
                return errno;
        }
        if ( ioctl(handle, SNDCTL_DSP_STEREO, &channels) == -1 ) {
                perror("ioctl stereo");
                return errno;
        }
        if ( ioctl(handle, SNDCTL_DSP_SETFMT, &format) == -1 ) {
                perror("ioctl format");
                return errno;
        }
        if ( ioctl(handle, SNDCTL_DSP_SPEED, &sample_rate) == -1 ) {
                perror("ioctl sample rate");
                return errno;
        }

        in_data_start_ptr = (short*)malloc(write_size);
        memset(in_data_start_ptr, 0, write_size);
        in_ptr = in_data_start_ptr;

        while (1)
        {
                in_ptr = in_data_start_ptr;
                
                //get input samples
                bytes_read = read(handle, in_ptr, write_size);
                if (bytes_read < 0)
                {
                        printf("problem reading input. goodbye.\n");
                        return -1;
                }
                else if (bytes_read < write_size)
                        printf("read: %d of %d\n", bytes_read, write_size);
                        
                //write them back out
                bytes_written = write(handle, in_ptr, write_size);
                if (bytes_written < 0)
                {
                        printf("problem writing output. goodbye.\n");
                        return -1;
                }
                else if (bytes_written < write_size)
                        printf("wrote: %d of %d\n", bytes_read, write_size);
        }
 
        return 0;
}

int main()
{
        soundthru();
        return 0;
 }

-- 
                        douglas irving repetto 
                  http://music.columbia.edu/~douglas 
                the music-dsp mailing list and website:
                  http://shoko.calarts.edu/musicdsp


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Mon Nov 27 2000 - 23:08:30 EET