Link to home
Start Free TrialLog in
Avatar of xiaominghng
xiaominghng

asked on

How to play a changing sound based on input value.

Hi there,

I have a probing application that accepts input from a USB device. It requires have a sound effect to indicting the input value. The input number would be 1 to 200. The application is developed in VB.Net. The sound should be from low to high ( pitch?) corresponding to the input value from low to high. I would appreciate any help or any sample code.
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Please re-explain what you are trying to do with input/output for sound.
Avatar of S-Twilley
S-Twilley

I think they need some sort of method like this:

Sub PlaySound(ByVal Frequency As Integer, ByVal Duration As Single)
    PlayPitchedSound(Frequency, Duration)
End Sub

=================

I've no idea how to implement playing a specific sound at a set frequency/pitch in VB.NET... used to know it in QBasic though :P

... so im interested in knowing the answer to this too
I should say that the PlayPitchedSound should be replace with some API call im guessing... im just writing out some naff pseudo code to maybe give you some idea of what I think they're after (if that makes sense)
Avatar of xiaominghng

ASKER

 Below is my code to play the sounds. I split a 4 seconds wav file (which has different pitches from low to high) to 200 wav files. I play each wav file according to the num. But it sounds awful. It is not very smooth. I want to make it sound like the 4 second wav file.

    Public Const SND_ASYNC = &H1 ' play asynchronously
    Public Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
    Public Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
    Public Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy


    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer


 PlaySound(Path & "Meter Wave" & CType(num, String) & ".wav", 0, SND_ASYNC Or SND_LOOP)

I would have thought there would be some API somewhere which works like the sound command (i forget the actual name) that was in QBasic... you could give a frequency in Hz... and the duration, and it would play that "note" for that set duration.

In QBasic, that gave you a continuous fluid note rather than a "joint" note... and obviously gave you more choice over the notes.

Hopefully someone knows of a similar API or command that can be brought into VB.NET
I think you will have to make(record) a wave that will have the sounds that you need. then call playsound to read only that small part of the wave file. I do that with a number grid program to read numbers.
Planocz,

Can you tell me how to read only small part of a wave file in VB .NET? Thanks
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial