linux speaker beep

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jgcrawford@gmail.com

    linux speaker beep

    G'day,
    I'm writing a ringtone manager for nokia ringtones and I'd like to be
    able to play the ringtone on the PC speaker. I've had some success in
    DOS with turbo C and its sound(), delay() and nosound(). Is there
    anything similar for Linux? I know I can make a simple beep with '\a',
    but that's not what I need. If not, can someone please show me how to
    do this with the /dev/audio device?

  • Joona I Palaste

    #2
    Re: linux speaker beep

    jgcrawford@gmai l.com <jgcrawford@gma il.com> scribbled the following:[color=blue]
    > G'day,
    > I'm writing a ringtone manager for nokia ringtones and I'd like to be
    > able to play the ringtone on the PC speaker. I've had some success in
    > DOS with turbo C and its sound(), delay() and nosound(). Is there
    > anything similar for Linux? I know I can make a simple beep with '\a',
    > but that's not what I need. If not, can someone please show me how to
    > do this with the /dev/audio device?[/color]

    If you want comp.unix.progr ammer, you know where to find it.

    --
    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "B-but Angus! You're a dragon!"
    - Mickey Mouse

    Comment

    • Malcolm

      #3
      Re: linux speaker beep


      <jgcrawford@gma il.com> wrote[color=blue]
      >
      > I'm writing a ringtone manager for nokia ringtones and I'd like to be
      > able to play the ringtone on the PC speaker. I've had some success in
      > DOS with turbo C and its sound(), delay() and nosound(). Is there
      > anything similar for Linux? I know I can make a simple beep with '\a',
      > but that's not what I need. If not, can someone please show me how to
      > do this with the /dev/audio device?
      >[/color]
      Audio is usually handled by third-party libraries, which are off-topic here.

      Unix being unix, it might be possible to open the audio device as a standard
      file using fopen(), and then write audio to it in some format or other.
      However you would have to ask in a unix group whether this is allowed, and
      if so what format the data has to be sent in.


      Comment

      • jgcrawford@gmail.com

        #4
        Re: linux speaker beep


        Joona I Palaste wrote:[color=blue]
        > jgcrawford@gmai l.com <jgcrawford@gma il.com> scribbled the following:[color=green]
        > > G'day,
        > > I'm writing a ringtone manager for nokia ringtones and I'd like to[/color][/color]
        be[color=blue][color=green]
        > > able to play the ringtone on the PC speaker. I've had some success[/color][/color]
        in[color=blue][color=green]
        > > DOS with turbo C and its sound(), delay() and nosound(). Is there
        > > anything similar for Linux? I know I can make a simple beep with[/color][/color]
        '\a',[color=blue][color=green]
        > > but that's not what I need. If not, can someone please show me how[/color][/color]
        to[color=blue][color=green]
        > > do this with the /dev/audio device?[/color]
        >
        > If you want comp.unix.progr ammer, you know where to find it.[/color]

        Well I didn't know that was the group I wanted, since the question I
        had involved DOS as well. I'll try reposting it there, thank you.

        Comment

        • Jack Klein

          #5
          Re: linux speaker beep

          On 18 Sep 2004 08:15:13 GMT, Joona I Palaste <palaste@cc.hel sinki.fi>
          wrote in comp.lang.c:
          [color=blue]
          > jgcrawford@gmai l.com <jgcrawford@gma il.com> scribbled the following:[color=green]
          > > G'day,
          > > I'm writing a ringtone manager for nokia ringtones and I'd like to be
          > > able to play the ringtone on the PC speaker. I've had some success in
          > > DOS with turbo C and its sound(), delay() and nosound(). Is there
          > > anything similar for Linux? I know I can make a simple beep with '\a',
          > > but that's not what I need. If not, can someone please show me how to
          > > do this with the /dev/audio device?[/color]
          >
          > If you want comp.unix.progr ammer, you know where to find it.[/color]

          Why do you keep redirecting people who specifically mention Linux in
          their OT questions to comp.unix.progr ammer? Linux != UNIX. The
          proper group for platform specific questions about Linux is
          news:comp.os.li nux.development .apps.

          If you are going to redirect, make the effort to redirect correctly.

          --
          Jack Klein
          Home: http://JK-Technology.Com
          FAQs for
          comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
          comp.lang.c++ http://www.parashift.com/c++-faq-lite/
          alt.comp.lang.l earn.c-c++

          Comment

          • Emmet Gorhsen

            #6
            Re: linux speaker beep

            Jack Klein wrote:
            [color=blue]
            > On 18 Sep 2004 08:15:13 GMT, Joona I Palaste
            > <palaste@cc.hel sinki.fi> wrote in comp.lang.c:
            >[color=green]
            >> jgcrawford@gmai l.com <jgcrawford@gma il.com> scribbled the
            >> following:
            >>[color=darkred]
            >> > G'day, I'm writing a ringtone manager for nokia ringtones
            >> > and I'd like to be able to play the ringtone on the PC
            >> > speaker. I've had some success in DOS with turbo C and its
            >> > sound(), delay() and nosound(). Is there anything similar
            >> > for Linux? I know I can make a simple beep with '\a', but
            >> > that's not what I need. If not, can someone please show me
            >> > how to do this with the /dev/audio device?[/color]
            >>
            >> If you want comp.unix.progr ammer, you know where to find it.[/color]
            >
            > Why do you keep redirecting people who specifically mention
            > Linux in their OT questions to comp.unix.progr ammer? Linux !=
            > UNIX. The proper group for platform specific questions about
            > Linux is news:comp.os.li nux.development .apps.
            >
            > If you are going to redirect, make the effort to redirect
            > correctly.
            >
            > --
            > OOOO OOOOO OOOO: OOOO://OO-OOOOOOOOOO.OOO OOOO OOO
            > OOOO.OOOO.O OOOO://OOO.OOOOOO.OOO/~OOO/O-OOO/OOO.OOOO
            > OOOO.OOOO.O++ OOOO://OOO.OOOOOOOOO.O OO/O++-OOO-OOOO/
            > OOO.OOOO.OOOO.O OOOO.O-O++
            > OOOO://OOO.OOOOOOO.OOO OOO.OOO.OOO/~OOO/OOOO/OOO-OOOOO.OOOO[/color]

            Says a _jerk_ who is using his sig as a commercial.

            Comment

            • joshua crawford

              #7
              Re: linux speaker beep

              Emmet Gorhsen wrote:[color=blue]
              > Jack Klein wrote:[color=green]
              > > On 18 Sep 2004 08:15:13 GMT, Joona I Palaste
              > > <palaste@cc.hel sinki.fi> wrote in comp.lang.c:[color=darkred]
              > >> jgcrawford@gmai l.com <jgcrawford@gma il.com> scribbled the
              > >> following:
              > >>
              > >> > G'day, I'm writing a ringtone manager for nokia ringtones
              > >> > and I'd like to be able to play the ringtone on the PC
              > >> > speaker. I've had some success in DOS with turbo C and its
              > >> > sound(), delay() and nosound(). Is there anything similar
              > >> > for Linux? I know I can make a simple beep with '\a', but
              > >> > that's not what I need. If not, can someone please show me
              > >> > how to do this with the /dev/audio device?
              > >>
              > >> If you want comp.unix.progr ammer, you know where to find it.[/color]
              > >
              > > Why do you keep redirecting people who specifically mention
              > > Linux in their OT questions to comp.unix.progr ammer? Linux !=
              > > UNIX. The proper group for platform specific questions about
              > > Linux is news:comp.os.li nux.development .apps.
              > >
              > > If you are going to redirect, make the effort to redirect
              > > correctly.
              > >
              > > --
              > > OOOO OOOOO OOOO: OOOO://OO-OOOOOOOOOO.OOO OOOO OOO
              > > OOOO.OOOO.O OOOO://OOO.OOOOOO.OOO/~OOO/O-OOO/OOO.OOOO
              > > OOOO.OOOO.O++ OOOO://OOO.OOOOOOOOO.O OO/O++-OOO-OOOO/
              > > OOO.OOOO.OOOO.O OOOO.O-O++
              > > OOOO://OOO.OOOOOOO.OOO OOO.OOO.OOO/~OOO/OOOO/OOO-OOOOO.OOOO[/color]
              >
              > Says a _jerk_ who is using his sig as a commercial.[/color]

              Says a jerk whose sole point in posting is to call another person a
              jerk. I must say I love the atmosphere in here. Thanks to Joona for the
              pointer to comp.unix.progr ammer. My problem is mostly resolved now.

              Comment

              • Keith Thompson

                #8
                Re: [OT] linux speaker beep

                Emmet Gorhsen <gorhsen@sailaw ay.net> writes:[color=blue]
                > Jack Klein wrote:[/color]
                [snip][color=blue][color=green]
                >> --
                >> OOOO OOOOO OOOO: OOOO://OO-OOOOOOOOOO.OOO OOOO OOO
                >> OOOO.OOOO.O OOOO://OOO.OOOOOO.OOO/~OOO/O-OOO/OOO.OOOO
                >> OOOO.OOOO.O++ OOOO://OOO.OOOOOOOOO.O OO/O++-OOO-OOOO/
                >> OOO.OOOO.OOOO.O OOOO.O-O++
                >> OOOO://OOO.OOOOOOO.OOO OOO.OOO.OOO/~OOO/OOOO/OOO-OOOOO.OOOO[/color]
                >
                > Says a _jerk_ who is using his sig as a commercial.[/color]

                Jack Klein's sig, which you apparently found so offensive you felt the
                need to obfuscate it, contains his name and homepage (which is hardly
                unusual), plus links to three FAQs which are extremely helpful to
                readers of this newsgroup. (One could could argue the topicality of
                the comp.lang.c++ FAQ, but topicality rules don't apply to sigs.) For
                that matter, his homepage could be considered a form of harmless
                advertising, but it also contains links to some useful information.

                Quick summary: You're wrong.

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • Moonie

                  #9
                  Re: linux speaker beep


                  try this....Moonie

                  you might need to use -DUSE_WIN32 or -DUSE_DOS or -DUSE_LINUX
                  and if using win32 to include windows and use dos to include dos.h an
                  i believe i have include the right headers for linux..off topic o
                  course. you can scream at my programming later.



                  #include <time.h>

                  void DELAY( int msec )
                  { clock_t goal;
                  goal = (clock_t) msec + clock();
                  while ( goal > clock() );
                  }


                  #if defined(USE_WIN 32)

                  void DoSound( unsigned int freq, unsigned int time )
                  {
                  Beep( freq, time );
                  return;
                  }

                  #elif defined(USE_DOS )
                  #if defined(__DJGPP __)
                  #undef nosound

                  void nosound(void)
                  {
                  sound(0);
                  return;
                  }

                  void DoSound(unsigne d int freq, unsigned int time)
                  {
                  sound(freq);
                  DELAY(time);
                  nosound();
                  return;
                  }
                  #elif defined(HAVE_SO UND)
                  void DoSound(unsigne d int freq, unsigned int time)
                  {
                  sound(freq);
                  DELAY(time);
                  nosound();
                  return;
                  }
                  #else
                  #ifndef LOBYTE
                  #define LOBYTE(w) ((BYTE) (w))
                  #endif

                  #ifndef HIBYTE
                  #define HIBYTE(w) ((BYTE) (((USHORT) (w) >> 8) & 0xFF))
                  #endif

                  EXTERN void HWSound( unsigned );
                  EXTERN void HWNoSound( void );

                  void HWSound(unsigne d int freq)
                  {
                  USHORT counter = 1193280 / freq; /* cycle counter */

                  outp(0x43, 0xB6); /* prepare timer */
                  outp(0x42, LOBYTE(counter) ); /* send low byte */
                  outp(0x42, HIBYTE(counter) ); /* send high byte */
                  outp(0x61, inp(0x61) | 0x03); /* turn speaker ON */
                  return;
                  }

                  void HWNoSound(void)
                  {
                  outp(0x61, inp(0x61) & 0xFC); /* turn speaker OFF */
                  return;
                  }

                  void DoSound(unsigne d int freq, unsigned int time)
                  {
                  HWSound(freq);
                  DELAY(time);
                  HWNoSound();
                  return;
                  }

                  #endif
                  #else
                  #include <asm/io.h>
                  #include <signal.h>
                  #include <stdio.h>

                  #define outp outb
                  #define inp inb

                  #ifndef LOBYTE
                  #define LOBYTE(w) ((BYTE) (w))
                  #endif

                  #ifndef HIBYTE
                  #define HIBYTE(w) ((BYTE) (((USHORT) (w) >> 8) & 0xFF))
                  #endif

                  EXTERN void HWSound( unsigned );
                  EXTERN void HWNoSound( void );

                  void HWSound(unsigne d int freq)
                  {
                  USHORT counter = 1193280 / freq; /* cycle counter */

                  outp(0x43, 0xB6); /* prepare timer */
                  outp(0x42, LOBYTE(counter) ); /* send low byte */
                  outp(0x42, HIBYTE(counter) ); /* send high byte */
                  outp(0x61, inp(0x61) | 0x03); /* turn speaker ON */
                  return;
                  }

                  void HWNoSound(void)
                  {
                  outp(0x61, inp(0x61) & 0xFC); /* turn speaker OFF */
                  return;
                  }

                  void DoSound(unsigne d int freq, unsigned int time)
                  {
                  HWSound(freq);
                  DELAY(time);
                  HWNoSound();
                  return;
                  }
                  #endi


                  -
                  Mooni
                  -----------------------------------------------------------------------
                  Posted via http://www.codecomments.co
                  -----------------------------------------------------------------------

                  Comment

                  • joshua crawford

                    #10
                    Re: linux speaker beep

                    Moonie wrote:[color=blue]
                    > try this....Moonie
                    >
                    > you might need to use -DUSE_WIN32 or -DUSE_DOS or -DUSE_LINUX
                    > and if using win32 to include windows and use dos to include dos.h[/color]
                    and[color=blue]
                    > i believe i have include the right headers for linux..off topic of
                    > course. you can scream at my programming later.[/color]

                    Thanks. I don't use windows, and turbo c already has sound(). The linux
                    code segfaults on the first outp(). Looking at the man page, it seems
                    outb() must be
                    preceeded by a call to ioperm(), which needs root permissions. I
                    already have a solution that works for root (using ioctl()) from
                    comp.unix.progr ammer. Thanks again, anyway.

                    Comment

                    Working...