Logo Search packages:      
Sourcecode: tucnak2 version File versions  Download package

soundwrapper.c

/*
    Tucnak - VHF contest log
    Copyright (C) 2002-2006  Ladislav Vaiz <ok1zia@nagano.cz>

    This program is free software; you can redistribute it and/or                                                        
    modify it under the terms of the GNU General Public License                                                          
    version 2 as published by the Free Software Foundation.

*/

#include "../config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>


#ifdef KIOCSOUND 

int main(int argc, char *argv[]){
    int ret, fd, freq, arg;

    fd=open("/dev/console", O_WRONLY|O_SYNC);
    if (fd<0) {
        fprintf(stderr, "Can't open /dev/console, error %d %s\n", errno, strerror(errno));
        return 1;
    }
    
    while(1){
        ret=read(0, &freq, sizeof(freq));
        if (ret!=sizeof(freq)){
            close(fd);
            fprintf(stderr, "Can't read %d bytes from /dev/console (only %d), error %d %s\n", (int)sizeof(freq), ret, errno, strerror(errno));
            return 1;
        }
        if (freq==-1) break;
        if ((freq!=0 && freq<50) || freq>20000) continue;
        if (freq) 
            arg=1192180/freq;
        else 
            arg=0;
        
        ret=ioctl(fd, KIOCSOUND, arg);
        if (ret){
            close(fd);
            fprintf(stderr, "Can't run IOCTL KIOCSOUND, error %d %s\n", errno, strerror(errno));
            return 1;
        }

    }
    close(fd);
    return 0;
}

#else

int main(int argc, char *argv[]){
    fprintf(stderr, "ioctl(KIOCSOUND) not supported on this sytem\n");
}

#endif

Generated by  Doxygen 1.6.0   Back to index