Solved

Playing RAW .pcm sound files

Posted on 2001-08-09
14
1,106 Views
Last Modified: 2012-06-22
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
Comment
Question by:pr80
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6370870
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
 
LVL 3

Expert Comment

by:andysalih
ID: 6370879
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
 

Author Comment

by:pr80
ID: 6370900
The files I need to play are RAW .PCM files not .WAV files and they do not play using a .WAV player
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6371037
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
 
LVL 2

Accepted Solution

by:
dmarco earned 100 total points
ID: 6376239
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
 
LVL 2

Expert Comment

by:dmarco
ID: 6377581
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
 

Author Comment

by:pr80
ID: 6379296
Thank you for your response.

The link to the RAW/WAV converter is dead.

Do you have any other links.

Thanks
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:pr80
ID: 6379777
Also I must add the .pcm files are a-law format
0
 
LVL 2

Expert Comment

by:dmarco
ID: 6382271
0
 
LVL 2

Expert Comment

by:dmarco
ID: 6382288
0
 
LVL 2

Expert Comment

by:dmarco
ID: 6382301
0
 
LVL 2

Expert Comment

by:dmarco
ID: 6382884
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7199883
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
 
LVL 5

Expert Comment

by:Netminder
ID: 7213352
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now