Question

I'm trying to make a beep sound with a frequency and a duration, i'm using ioctl and a file with the console path (I think it is right, i'm using debian 6, by the way) but i don't know why it doesn't work. The code reaches the line ioctl, but it doesn't beep. Im working in a Virtual Machine. The drivers should not be the problem because i have installed my own driver that controls the keyboard leds and makes no problem.

(I have followed this example: http://linuxplayer.org/2010/04/beep-your-pc-speaker-in-linux)

#include <sys/ioctl.h>
#include <linux/kd.h>

int bip;
#define consolepath "/dev/console"
//#define consolepath "/dev/tty0"

void beep (int freq, int dur){
    int aux;
    if ( (bip = open(consolepath, 'w')) == -1 ) {
        printf ("console unreachable/dev/console!\n" );
    }else{
        //fprintf(bip, "%c[10;%d]%c[11;%d]\a", ESC, freq, ESC, dur);    //Another different try
        ioctl(bip, KDMKTONE, (dur<<16 | 1193180/freq));

        close(bip);

    }
}
Was it helpful?

Solution 2

The problem was with my OS, i was executing Debian 6 in VMWare Workstation, and the port mapping is not well done, so i couldn't do it.

OTHER TIPS

I don't know if that fixes your problem, but the "oflag" argument given to open() should be O_WRONLY or perhaps O_RDWR, but not the character 'w'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top