• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1372
  • Last Modified:

Playing RAW .pcm sound files

I am writing an application that needs to play sound files in RAW .pcm format (8000khz 8bit mono a-law).

Does anyone know how I can do this in VB6

Thanks
0
pr80
Asked:
pr80
  • 6
  • 3
  • 3
  • +2
1 Solution
 
andysalihCommented:
dunno,

but have a look at this anyway


Option Explicit


Private Sub Command1_Click()
    Dim FileNumber As Integer
    Dim I As Single
    Dim Min As Single
    Dim Max As Single
    Dim Temp As Integer
    Dim XZoomrate As Single
    Dim YZoomrate As Single
    Dim LastX As Single
    Dim LastY As Single
    On Error GoTo ErrorHandler
    ' Enable Cancel error


    With Picture1
        CommonDialog1.CancelError = True
        CommonDialog1.Filter = "Wave files (*.wav)|*.wav"
        CommonDialog1.ShowOpen
        ' Change the caption of the form
        Me.Caption = CommonDialog1.filename
        I = 44 ' Set I To 44, since the wave sample is begin at Byte 44.
        ' Open file to get the length of the wav
        '    
        'e file.
        FileNumber = FreeFile
        Open CommonDialog1.filename For Random As #FileNumber


        Do
            Get #FileNumber, I, Temp
            I = I + 1
            ' Get the smallest and largest number. T
            '    
            'hey will be use for the adjustment
            ' of the vertical size.
            If Temp < Min Then Min = Temp
            If Temp > Max Then Max = Temp
        Loop Until EOF(FileNumber)
        Close #FileNumber
        ' Adjust values and reset values
        XZoomrate = (.Width / I)
        YZoomrate = (Max - Min) / (.Height / 2)
        .CurrentX = 100
        .CurrentY = .Height / 2
        LastX = 100
        LastY = .Height / 2
        .AutoRedraw = True
        I = 44
        ' Reopen file using a different FileNumb
        '    
        'er
        FileNumber = FileNumber + 1
        .Cls
        Open CommonDialog1.filename For Random As #FileNumber


        Do
            Get #FileNumber, I, Temp
            ' Set CurrentX and CurrentY
            .CurrentX = .CurrentX + XZoomrate
            .CurrentY = (Temp / YZoomrate) + .Height / 2
            ' Plot graph
            Picture1.Line (LastX, LastY)-(.CurrentX, .CurrentY), vbBlack
            ' Reset values
            LastX = .CurrentX
            LastY = .CurrentY
            I = I + 1
           
            If .CurrentX > .Width Then Exit Do
        Loop Until EOF(FileNumber)
        Close #FileNumber
    End With
   
    ErrorHandler:
    ' Do nothing
End Sub


Private Sub Form_Resize()
    On Error Resume Next
    ' Resize control


    With Picture1
        .BackColor = vbWhite
        .ForeColor = vbBlack
        .Move 50, 500, Width - 200, Height - 800
    End With
End Sub

cheers
Andy
0
 
andysalihCommented:
also just to play a WAV

this was a previously accepted answer by me do the following

ttry this


Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String,
ByVal uFlags As Long) As Long
   Then to call the API type:
   Variable = sndPlaySound (Location, 1)
   So for example to play a .wav file located at C:\Sounds\sound.wav type:
   Variable = sndPlaySound ("C:\Sounds\sound.wav, 1)


thats it

andy


but that will only play WAV's not PCM's i dont know if it matters

0
 
pr80Author Commented:
The files I need to play are RAW .PCM files not .WAV files and they do not play using a .WAV player
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
andysalihCommented:
well i dont know how to then .... sorry matey, i tried. even myself as an EE expert has limitations (lol)

dont worry somebody will come with a solution im sure,

cheers
Andy
0
 
dmarcoCommented:
If you don't find a way to play RAW files in VB, you can convert them into WAV files. Here a link to get a RAW to WAV converter (runs under DOS 6.0):

http://cnet.search.com/click?sl,techsearch.2.103.426.0.1.RAW+audio.0,http%3A%2F%2Fdownload%2Ecnet%2Ecom%2Fdownloads%2F0%2D1896417%2D100%2D1517841%2Ehtml

(it is also available a WAV to RAW conv.)
hope this helps
0
 
dmarcoCommented:
Some more info about RAW PCM audio format.
 PCM stands for Pulse Code Modulation and is a particular kind of sampling: the values of digital converted samples are actual values and not differences between subsequent samples. However, this is the default audio encoding system used with waw files by Windows. You should also know sampling frequency (usually from 8 to 44 kHz) and amplitude (8 or 16 bits) related to your PCM format.
About RAW file type: RAW sound files are simply stored exactly as they are in memory, e.g. an 8-bit mono RAW file consists of bytes that specify the volume of the sound. RAW FILES CONTAIN NO HEADER.
Conclusion:  a RAW PCM file is the same that a WAW PCM without file header.
My personal advice is to do the following: convert RAW to WAW, play WAW (with sndPlaySound API or MMControl) and, if necessary, convert WAW to RAW.  You shouldn't get loss of quality. On the web, you can find easily a lot of RAW/WAW converter. If you need, I can give you the links (other than that of the previous comment).

Regards


0
 
pr80Author Commented:
Thank you for your response.

The link to the RAW/WAV converter is dead.

Do you have any other links.

Thanks
0
 
pr80Author Commented:
Also I must add the .pcm files are a-law format
0
 
dmarcoCommented:
0
 
dmarcoCommented:
0
 
dmarcoCommented:
0
 
dmarcoCommented:
Sorry, I wasn't able to post my comment ... I have got 3 times an internal server error at EE. I tried also to contact the CS, but it seemed that nothing was working some hours ago..

Here there are the links for you:


http://www.fmjsoft.com/awaveaudio.html

Awave Audio is a (shareware) dedicated audio file format batch converter.

Do conversions from the about 60 audio file formats that it can read into any of the 30 or so audio file formats that it writes!  

supports:
.....
RAW     R+W     Raw signed PCM data.
....
WAV     R+W     Ms Windows PCM wave.
WAV     R+W     'Extensible format' Microsoft Waveform file.
-----------------------------------------------------------------------------------------

http://www.nctsoft.com/products/NCTMediaConverter/

The NCT Media Converter is a (shareware) universal converter and grabber of audio files

WAV PCM;
compressed WAV (ADPCM, GSM, DSP, A-LAW, U-LAW, ALF2 and others);
MP3 (MPEG Layer-3);
VOX (Dialogic ADPCM);
WMA (Windows Media Audio);
RAW (PCM, A-LAW, U-LAW);
CDA (Audio CD Tracks).
-----------------------------------------------------------------------

http://www.audioconvert.com/

AudioConvert is a ( $ 29,95) professional solution for converting, ripping, transforming and recording all types of audio files.
Converting WAV, MP3, WMA, GSM, G.726, RAW, VOX, ACM, ADPCM, and DSP audio
---------------------------------------------------------------------------

Unfortunately I couldn't find any freeware that seemed reliable.

Notice that PCM 8 bit, mono, 8 kHz is one kind of encoding. I believe that a-Law is a different one.... so, check your file(s) property before performing the conversion.

good luck

Marco
 


 
0
 
DanRollinsCommented:
Hi pr80,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept dmarco's comment(s) as an answer.

pr80, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
NetminderCommented:
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now