[Solved] Sound advise

Post

Posted
Rating:
#1 (In Topic #1100)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi Everyone

so I need someone who is smarter then me (so that is everyone lol)

I have a slight issue that I am not sure how to sort out

I can run this command with in Gambas

Code (gambas)

  1. Dim SpeakerData As String = Null
  2. SpeakerData = "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
  3. Shell SpeakerData
  4.  
  
and it works fine but  when I run

Code (gambas)

  1.  shell "play -n synth 0.1 sine 880 vol 5"

i get nothing but when run the play command with in a terminal i get a nice loud beep

SO am I doing something wrong here or am i missing a command that i need to use?

Any ideas are MOST welcomed
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
seems play does not release/end the shell process as it needs an stdout.

try it with & at the end of the command or running 'Shell sCommand for Output' …

Code (gambas)

  1. shell "play -n synth 0.1 sine 880 vol 5 &"
  2.  

Or this….

Code (gambas)

  1. shell "play -n synth 0.1 sine 880 vol 5" For Output
  2.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
vuott is in the usergroup ‘Regular’
……why not just use the resources of Gambas ?  :roll:

You need to activate <COLOR color="#800000">gb.openal</COLOR> Component:

Code (gambas)

  1. Private Const AMPLITUDO As Integer = 127
  2. Private Const FRECUENTIA As Integer = 880
  3. Private Const DIGIT As Integer = 44100
  4. Private Const TEMPUS As Single = 0.15
  5.  
  6.  
  7. Public Sub Main()
  8.  
  9.   Dim disp As AlcDevice
  10.   Dim cont As AlcContext
  11.   Dim src, buffer As Integer[]
  12.   Dim err As Boolean
  13.   Dim data As New Byte[]
  14.  
  15. ' Configures the device and the audio context with the "Alc" Class:
  16.    disp = Alc.OpenDevice(Null)
  17.    cont = Alc.CreateContext(disp)
  18.  
  19.    err = cont.MakeCurrent()
  20.    If err = False Then Error.Raise("Error !")
  21.  
  22.    src = Al.GenSources(1)
  23.  
  24. ' Configures the audio buffer:
  25.    buffer = Al.GenBuffers(1)
  26.  
  27.    Wave(data)
  28.  
  29. ' The audio data is loaded into the audio buffer:
  30.    Al.BufferData(buffer[0], 4352, data.Data, data.Count, DIGIT)
  31.  
  32. ' Connects the audio buffer to the audio source:
  33.    Al.Sourcei(src[0], Al.BUFFER, buffer[0])
  34.  
  35. ' Play the audio source:
  36.    Al.SourcePlay(src[0])
  37.  
  38. ' Allows performance for the entire duration of the sound wave:
  39.    Wait TEMPUS
  40.  
  41. ' Releases the memory:
  42.    Al.DeleteBuffers(buffer)
  43.    Al.DeleteSources(src)
  44.    Alc.DestroyContext(cont)
  45.    Alc.CloseDevice(disp)
  46.  
  47.  
  48.  
  49. Private Function Wave(bb As Byte[])    ' Creates the sine wave audio data
  50.  
  51.  
  52.    For i = 0 To (TEMPUS * 2 * DIGIT) - 1
  53.      bb.Push(CByte(128 + AMPLITUDO * Sin(CFloat(i / DIGIT * FRECUENTIA * (2 * Pi)))))
  54.    Next
  55.  

or by using <COLOR color="#800000">gb.media</COLOR> resources:

Code (gambas)

  1. Public Sub Main()
  2.  
  3.   Dim pl As New MediaPipeline
  4.   Dim src, snk As MediaControl
  5.  
  6.   src = New MediaControl(pl, "audiotestsrc")
  7.   src["freq"] = "880"
  8.   src["wave"] = 0     ' A value of 0 allows a sine wave to be reproduced
  9.   snk = New MediaControl(pl, "autoaudiosink")
  10.  
  11.   src.LinkTo(snk)
  12.  
  13.   pl.Play()
  14.  
  15.   Wait 0.15
  16.  
  17.   pl.Close
  18.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’

Code (gambas)

  1. Dim SpeakerData As String = Null
  2. SpeakerData = "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
  3. Shell SpeakerData
  4.  

There is no need for = Null, you could have just followed the equal sign with "speaker - test -t…..". Better still: -

Code (gambas)

  1. Shell "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
Which works for me
************************************

Code (gambas)

  1. shell "play -n synth 0.1 sine 880 vol 5"
  2.  

You are correct, it doesn't work, and I have no idea why.

If you want to make sounds in Gambas, I suggest you make a recoding of what you want or get one from the internet, there are plenty of sites with free sounds you can download. You can then use code as below: -

Code (gambas)

  1. Music.Load(User.Home &/ "MySound.ogg") ''Requires gb.sdl2.audio
  2. Music.Play  
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

cogier said

Code (gambas)

  1. Dim SpeakerData As String = Null
  2. SpeakerData = "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
  3. Shell SpeakerData
  4.  

There is no need for = Null, you could have just followed the equal sign with "speaker - test -t…..". Better still: -

Code (gambas)

  1. Shell "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
Which works for me
************************************

Code (gambas)

  1. shell "play -n synth 0.1 sine 880 vol 5"
  2.  

You are correct, it doesn't work, and I have no idea why.

If you want to make sounds in Gambas, I suggest you make a recoding of what you want or get one from the internet, there are plenty of sites with free sounds you can download. You can then use code as below: -

Code (gambas)

  1. Music.Load(User.Home &/ "MySound.ogg") ''Requires gb.sdl2.audio
  2. Music.Play  

The problem with the above is the systems I am using do not have any sound cards on them they only have the PC speaker.
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Try:
play -V3 -n synth 0.1 sine 880 vol 0.4

vol 5 means 5 times the normal volume which clips to a DC voltage.

Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
vuott is in the usergroup ‘Regular’

AndyGable said

…do not have any sound cards on them they only have the PC speaker.
Have you tried the :? old ways…

Code (gambas)

  1. Print "\x07"
and

Code (gambas)

  1. Shell "printf '\x07'"
or this by using the external ioctl() function:

Code (gambas)

  1. Library "libc:6"
  2.  
  3. Private Const KIOCSOUND As Integer = &4B2F
  4.  
  5. ' int ioctl(int __fd, unsigned long int __request, ...)
  6. ' Perform the I/O control operation specified by REQUEST on FD.
  7. Private Extern ioctl(__fd As Integer, __request As Long, arg As Long) As Integer
  8.  
  9.  
  10. Public Sub Main()
  11.  
  12.   Dim freq As Short[] = [523, 587, 659, 698, 784, 880, 988, 1046]
  13.   Dim fl As File
  14.   Dim i, err As Integer
  15.  
  16.   Shell "echo MY_PASSWORD | sudo -S chmod 666 '/dev/tty0'" Wait
  17.  
  18.   fl = Open "/dev/tty0" For Write
  19.  
  20.   For i = 0 To 7
  21.     err = ioctl(fl.Handle, KIOCSOUND, 1193180 / freq[i])
  22.     If err == -1 Then Error.Raise("Error !")
  23.     Wait 200
  24.     err = ioctl(fl.Handle, KIOCSOUND, 0)
  25.     If err == -1 Then Error.Raise("Error !")
  26.   Next
  27.  
  28.   fl.Close
  29.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#8
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

thatbruce said

Try:
play -V3 -n synth 0.1 sine 880 vol 0.4

vol 5 means 5 times the normal volume which clips to a DC voltage.

I tried this one and I got the following show up in the console of the Gambas enveroment.

Code (gambas)

  1. play WARN alsa: can't encode 0-bit Unknown or not applicable
  2. play:      SoX v14.4.2
  3. play INFO nulfile: sample rate not specified; using 48000
  4.  
  5. Input File     : '' (null)
  6. Channels       : 1
  7. Sample Rate    : 48000
  8. Precision      : 32-bit
  9.  
  10.  
  11. Output File    : 'default' (alsa)
  12. Channels       : 1
  13. Sample Rate    : 48000
  14. Precision      : 32-bit
  15. Sample Encoding: 32-bit Signed Integer PCM
  16. Endian Type    : little
  17. Reverse Nibbles: no
  18. Reverse Bits   : no
  19.  
  20. play INFO sox: effects chain: input        48000Hz  1 channels
  21. play INFO sox: effects chain: synth        48000Hz  1 channels
  22. play INFO sox: effects chain: vol          48000Hz  1 channels
  23. play INFO sox: effects chain: output       48000Hz  1 channels
  24.  

and no sound
Online now: No Back to the top

Post

Posted
Rating:
#9
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

vuott said

Have you tried the :? old ways…

Code (gambas)

  1. Print "\x07"
and

Code (gambas)

  1. Shell "printf '\x07'"
or this by using the external ioctl() function:

Code (gambas)

  1. Library "libc:6"
  2.  
  3. Private Const KIOCSOUND As Integer = &4B2F
  4.  
  5. ' int ioctl(int __fd, unsigned long int __request, ...)
  6. ' Perform the I/O control operation specified by REQUEST on FD.
  7. Private Extern ioctl(__fd As Integer, __request As Long, arg As Long) As Integer
  8.  
  9.  
  10. Public Sub Main()
  11.  
  12.   Dim freq As Short[] = [523, 587, 659, 698, 784, 880, 988, 1046]
  13.   Dim fl As File
  14.   Dim i, err As Integer
  15.  
  16.   Shell "echo MY_PASSWORD | sudo -S chmod 666 '/dev/tty0'" Wait
  17.  
  18.   fl = Open "/dev/tty0" For Write
  19.  
  20.   For i = 0 To 7
  21.     err = ioctl(fl.Handle, KIOCSOUND, 1193180 / freq[i])
  22.     If err == -1 Then Error.Raise("Error !")
  23.     Wait 200
  24.     err = ioctl(fl.Handle, KIOCSOUND, 0)
  25.     If err == -1 Then Error.Raise("Error !")
  26.   Next
  27.  
  28.   fl.Close
  29.  

Yes I did try the above the \x07 just flashed the screen at me and no sound and the other asked for my password and then errored out at Error !
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
vuott is in the usergroup ‘Regular’
Uhmmm… some time ago, stevedee proposed using the "Screen" Class of "<COLOR color="#800000">gb.ncurses</COLOR>" Component.
Try:

Code (gambas)

  1. Public Sub Main()
  2.  
  3.   Screen.Beep()
  4.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#11
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

vuott said

Uhmmm… some time ago, stevedee proposed using the "Screen" Class of "<COLOR color="#800000">gb.ncurses</COLOR>" Component.
Try:

Code (gambas)

  1. Public Sub Main()
  2.  
  3.   Screen.Beep()
  4.  

I have tried your recommendation but I kept getting a error

ERROR: #63: '&1.&2' is incorrectly overridden in class '&3'|Screen|Height|Screen

If I remove the gb.ncurses the application runs with no issues.
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
vuott is in the usergroup ‘Regular’

AndyGable said

ERROR: #63: '&1.&2' is incorrectly overridden in class '&3'|Screen|Height|Screen
You have to use "gb.ncurses" with a command line interface project (no graphics Components):

Code (gambas)

  1. Public Sub Main()

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#13
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
No I was using it with a GUI qt5
Online now: No Back to the top

Post

Posted
Rating:
#14
Regular
vuott is in the usergroup ‘Regular’
…and by using a command line interface project (with gb.ncurses obviously) ?
Does it work ?

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

AndyGable said

thatbruce said

Try:
play -V3 -n synth 0.1 sine 880 vol 0.4

vol 5 means 5 times the normal volume which clips to a DC voltage.

I tried this one and I got the following show up in the console of the Gambas enveroment.

Code (gambas)

  1. play WARN alsa: can't encode 0-bit Unknown or not applicable
  2. play:      SoX v14.4.2
  3. play INFO nulfile: sample rate not specified; using 48000
  4.  
  5. Input File     : '' (null)
  6. Channels       : 1
  7. Sample Rate    : 48000
  8. Precision      : 32-bit
  9.  
  10.  
  11. Output File    : 'default' (alsa)
  12. Channels       : 1
  13. Sample Rate    : 48000
  14. Precision      : 32-bit
  15. Sample Encoding: 32-bit Signed Integer PCM
  16. Endian Type    : little
  17. Reverse Nibbles: no
  18. Reverse Bits   : no
  19.  
  20. play INFO sox: effects chain: input        48000Hz  1 channels
  21. play INFO sox: effects chain: synth        48000Hz  1 channels
  22. play INFO sox: effects chain: vol          48000Hz  1 channels
  23. play INFO sox: effects chain: output       48000Hz  1 channels
  24.  

and no sound

OK, That's almost exactly what I get, with the beep very audible. The only difference is
Output File    : 'default' (pulseaudio)
Do you have pulseaudio installed. (I have no idea why it should be needed, btw)
tb

OOPS! I also get this at the end:
In:0.00% 00:00:00.17 [00:00:00.00] Out:4.80k [ -===‡===- ]        Clip:0    
Done.

Online now: No Back to the top

Post

Posted
Rating:
#16
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
BTW, A4 is one of the most annoying sounds in the universe.
Try C3 523.25Hz
 ;)

Online now: No Back to the top

Post

Posted
Rating:
#17
Guru
BruceSteers is in the usergroup ‘Guru’
 How about installing beep?

sudo apt install beep


beep
Online now: No Back to the top

Post

Posted
Rating:
#18
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

How about installing beep?

sudo apt install beep


beep

Yea I did that and and it worked but it was the quietest beep ever lol

I need to work out how to beep the Dynakey built in speaker and not the one on the motherboard now I can make the beep sound.
Online now: No Back to the top

Post

Posted
Rating:
#19
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

cogier said

Code (gambas)

  1. Dim SpeakerData As String = Null
  2. SpeakerData = "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
  3. Shell SpeakerData
  4.  

There is no need for = Null, you could have just followed the equal sign with "speaker - test -t…..". Better still: -

Code (gambas)

  1. Shell "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
Which works for me
************************************

Code (gambas)

  1. shell "play -n synth 0.1 sine 880 vol 5"
  2.  

You are correct, it doesn't work, and I have no idea why.

The problem with the above is the systems I am using do not have any sound cards on them they only have the PC speaker.

Did you miss my post?  It requires stdout or the play command does not exit so use "&" or "For Output" when using gambas Shell process then it can continue

Code (gambas)

  1. Shell "play -n synth 0.1 sine 880 &"
  2.  
or

Code (gambas)

  1. Shell "play -n synth 0.1 sine 880" For Output
  2.  
They both work fine here

Code (gambas)

  1. Shell "play -n synth 0.1 sine 880 2>/dev/null &"
  2.  
if you want to divert the text output (stderr) to null
Online now: No Back to the top

Post

Posted
Rating:
#20
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

AndyGable said

cogier said



There is no need for = Null, you could have just followed the equal sign with "speaker - test -t…..". Better still: -

Code (gambas)

  1. Shell "speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!"
Which works for me
************************************


You are correct, it doesn't work, and I have no idea why.

The problem with the above is the systems I am using do not have any sound cards on them they only have the PC speaker.

Did you miss my post?  It requires stdout or the play command does not exit so use "&" or "For Output" when using gambas Shell process then it can continue

Code (gambas)

  1. Shell "play -n synth 0.1 sine 880 &"
  2.  
or

Code (gambas)

  1. Shell "play -n synth 0.1 sine 880" For Output
  2.  
They both work fine here

Code (gambas)

  1. Shell "play -n synth 0.1 sine 880 2>/dev/null &"
  2.  
if you want to divert the text output (stderr) to null

Sorry Bruce I did miss your post

and it works perfectly

NOW If I am reading this information right
Speaker

The 5953 includes a built‐in speaker. By default, it sounds key clicks, but it can
be programmed to sound tones under control of the application program.

The speaker is tied to the speaker control of the host terminal so that whenever the
terminal speaker sounds, so does the 5953 speaker


I should not have to worry about the DynaKey Speaker it should work with the current Shell "play -n synth 0.1 sine 880" For Output. I will have to test this in the morning when I am near my NCR machine again and I will let you all know.

this is the NCR Dynakey Manual (https://manualzz.com/d…b-dynakey-user-manual#p15)
Online now: No Back to the top

Post

Posted
Rating:
#21
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’

AndyGable said

Yea I did that and and it worked but it was the quietest beep ever lol

Fortunately not if you run this through a VT131 data terminal.  :lol:

I implemented this code when I was trying to port a quick test program I wrote in Commodore Basic on my VIC-20 to modern Linux using Gambas (and Lazarus).

Code

Exec ["play", "-n", "synth", "1", "sine", Rnd(1, 500)]

This will play a different tone each time.
Online now: No Back to the top
1 guest and 0 members have just viewed this.