Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default macro to create CSV from Wave File

Anyone know how to decode a wave file into it's two tables of data? I am
interested in coverting wave files to text. I think I have a macro somewhere
that writes a wave file, but I don't know how to reverse engineer it.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default macro to create CSV from Wave File

this is what I have for writing wave files. these command buttons say PLAY,
REC, and STOP.

' Add Winsock component using Excel View/Toolbars/Control Toolbox
' From Control Toolbox select More Controls icon, then Microsoft Winsock
Control

Public TCPvolts As Winsock
Public EndNow As Boolean

Private Sub CommandButton1_Click()
Dim unConverted, inData As String
Dim n0 As String, limit As Long, n As Long
Dim max As Single, min As Single, range As Single

EndNow = False
' 1. TCP/IP connection
Set TCPvolts = CreateObject("MSWinsock.Winsock.1")
TCPvolts.RemotePort = 888
TCPvolts.RemoteHost = Sheet1.Cells(13, 4)
Sheet1.Cells(22, 3).Value = "Connecting"
TCPvolts.Connect
While TCPvolts.State < sckConnected And Not EndNow
DoEvents
Wend

If EndNow Then
Sheet1.Cells(22, 3).Value = "Done"
Exit Sub
End If
Sheet1.Cells(22, 3).Value = "Playing"

' 2. Convert column A to voltage 0-255 and send

limit = Sheet1.Cells(17, 4).Value
max = Sheet1.Cells(1, 1).Value
min = Sheet1.Cells(1, 1).Value

For i = 1 To limit
If Sheet1.Cells(i, 1).Value max Then
max = Sheet1.Cells(i, 1).Value
End If
If Sheet1.Cells(i, 1).Value < min Then
min = Sheet1.Cells(i, 1).Value
End If
Next i

range = max - min

unConverted = ""
n = 0
data = ""
While n < limit And Not EndNow
n = n + 1
data = data + Chr(Round((Sheet1.Cells(n, 1) - min) / range * 255, 0))
DoEvents
Wend
If Not EndNow Then
TCPvolts.SendData data
End If
DoEvents
TCPvolts.Close
Sheet1.Cells(22, 3).Value = "Done"
End Sub
Private Sub CommandButton2_Click()
Dim unConverted, inData As String
Dim n0 As String, limit As Long, n As Long

EndNow = False

' 1. TCP/IP connection
Set TCPvolts = CreateObject("MSWinsock.Winsock.1")
TCPvolts.RemotePort = 888
Sheet1.Cells(22, 3).Value = "Connecting"
TCPvolts.RemoteHost = Sheet1.Cells(13, 4)
TCPvolts.Connect
While TCPvolts.State < sckConnected And Not EndNow
DoEvents
Wend

If EndNow Then
Sheet1.Cells(22, 3).Value = "Done"
Exit Sub
End If
Sheet1.Cells(22, 3).Value = "Recording"

' 2. Collect real-time raw data, convert, and display as voltage
unConverted = ""
n = 0
limit = Sheet1.Cells(17, 4).Value
While n < limit And Not EndNow
If TCPvolts.BytesReceived = 2 Or Len(unConverted) = 2 Then
n = n + 1
If Len(unConverted) + n < limit Then
TCPvolts.GetData inData ' Read data
unConverted = unConverted & inData
End If
n0 = Mid(unConverted, 1, 1)
Sheet1.Cells(n, 1).Value = Asc(n0) / 255
unConverted = Mid(unConverted, 2)
End If
DoEvents
Wend
TCPvolts.Close
Sheet1.Cells(22, 3).Value = "Done"
End Sub

Private Sub CommandButton3_Click()
EndNow = True
End Sub

Private Sub CommandButton4_Click() ' Write Wav file
Dim fs, f, filelen
Dim limit As Long, n As Long
Dim max As Single, min As Single, range As Single
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(ActiveWorkbook.Path + "\Excel.wav", True)
MsgBox "Sound written to " & ActiveWorkbook.Path + "\Excel.wav"

f.write "RIFF"
filelen = Sheet1.Cells(17, 4).Value + 36
'f.write Chr(&H64) ' file length - 8
'f.write Chr(&H1F)
'f.write Chr(&H0)
'f.write Chr(&H0)
f.write Chr(filelen Mod 256)
f.write Chr((filelen / 256) Mod 256)
f.write Chr((filelen / 256 / 256) Mod 256)
f.write Chr((filelen / 256 / 256 / 256) Mod 256)
f.write "WAVE"
f.write "fmt "
f.write Chr(16) ' Length of the fmt data (16 bytes)
f.write Chr(0)
f.write Chr(0)
f.write Chr(0)
f.write Chr(1) ' Format tag: 1 = PCM
f.write Chr(0)
f.write Chr(1) ' Channels: 1 = mono, 2 = stereo
f.write Chr(0)
f.write Chr(&H40) ' Samples per second: e.g., 8000
f.write Chr(&H1F)
f.write Chr(&H0)
f.write Chr(&H0)
f.write Chr(&H40) ' Sample rate * block align
f.write Chr(&H1F)
f.write Chr(&H0)
f.write Chr(&H0)
f.write Chr(1) ' channels * bits/sample / 8
f.write Chr(0)
f.write Chr(8) ' 8 or 16
f.write Chr(0)
f.write "data"
f.write Chr(Sheet1.Cells(17, 4).Value Mod 256)
f.write Chr((Sheet1.Cells(17, 4).Value / 256) Mod 256)
f.write Chr((Sheet1.Cells(17, 4).Value / 256 / 256) Mod 256)
f.write Chr((Sheet1.Cells(17, 4).Value / 256 / 256 / 256) Mod 256)

' Convert column A to voltage 0-255 and send
limit = Sheet1.Cells(17, 4).Value
max = Sheet1.Cells(1, 1).Value
min = Sheet1.Cells(1, 1).Value

For i = 1 To limit
If Sheet1.Cells(i, 1).Value max Then
max = Sheet1.Cells(i, 1).Value
End If
If Sheet1.Cells(i, 1).Value < min Then
min = Sheet1.Cells(i, 1).Value
End If
Next i

range = max - min

For i = 1 To Sheet1.Cells(17, 4).Value
f.write Chr(Round((Sheet1.Cells(i, 1) - min) / range * 255, 0))
Next i
f.Close
End Sub


"fugazi48" wrote:

Anyone know how to decode a wave file into it's two tables of data? I am
interested in coverting wave files to text. I think I have a macro somewhere
that writes a wave file, but I don't know how to reverse engineer it.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default macro to create CSV from Wave File

bump

"fugazi48" wrote:

this is what I have for writing wave files. these command buttons say PLAY,
REC, and STOP.

' Add Winsock component using Excel View/Toolbars/Control Toolbox
' From Control Toolbox select More Controls icon, then Microsoft Winsock
Control

Public TCPvolts As Winsock
Public EndNow As Boolean

Private Sub CommandButton1_Click()
Dim unConverted, inData As String
Dim n0 As String, limit As Long, n As Long
Dim max As Single, min As Single, range As Single

EndNow = False
' 1. TCP/IP connection
Set TCPvolts = CreateObject("MSWinsock.Winsock.1")
TCPvolts.RemotePort = 888
TCPvolts.RemoteHost = Sheet1.Cells(13, 4)
Sheet1.Cells(22, 3).Value = "Connecting"
TCPvolts.Connect
While TCPvolts.State < sckConnected And Not EndNow
DoEvents
Wend

If EndNow Then
Sheet1.Cells(22, 3).Value = "Done"
Exit Sub
End If
Sheet1.Cells(22, 3).Value = "Playing"

' 2. Convert column A to voltage 0-255 and send

limit = Sheet1.Cells(17, 4).Value
max = Sheet1.Cells(1, 1).Value
min = Sheet1.Cells(1, 1).Value

For i = 1 To limit
If Sheet1.Cells(i, 1).Value max Then
max = Sheet1.Cells(i, 1).Value
End If
If Sheet1.Cells(i, 1).Value < min Then
min = Sheet1.Cells(i, 1).Value
End If
Next i

range = max - min

unConverted = ""
n = 0
data = ""
While n < limit And Not EndNow
n = n + 1
data = data + Chr(Round((Sheet1.Cells(n, 1) - min) / range * 255, 0))
DoEvents
Wend
If Not EndNow Then
TCPvolts.SendData data
End If
DoEvents
TCPvolts.Close
Sheet1.Cells(22, 3).Value = "Done"
End Sub
Private Sub CommandButton2_Click()
Dim unConverted, inData As String
Dim n0 As String, limit As Long, n As Long

EndNow = False

' 1. TCP/IP connection
Set TCPvolts = CreateObject("MSWinsock.Winsock.1")
TCPvolts.RemotePort = 888
Sheet1.Cells(22, 3).Value = "Connecting"
TCPvolts.RemoteHost = Sheet1.Cells(13, 4)
TCPvolts.Connect
While TCPvolts.State < sckConnected And Not EndNow
DoEvents
Wend

If EndNow Then
Sheet1.Cells(22, 3).Value = "Done"
Exit Sub
End If
Sheet1.Cells(22, 3).Value = "Recording"

' 2. Collect real-time raw data, convert, and display as voltage
unConverted = ""
n = 0
limit = Sheet1.Cells(17, 4).Value
While n < limit And Not EndNow
If TCPvolts.BytesReceived = 2 Or Len(unConverted) = 2 Then
n = n + 1
If Len(unConverted) + n < limit Then
TCPvolts.GetData inData ' Read data
unConverted = unConverted & inData
End If
n0 = Mid(unConverted, 1, 1)
Sheet1.Cells(n, 1).Value = Asc(n0) / 255
unConverted = Mid(unConverted, 2)
End If
DoEvents
Wend
TCPvolts.Close
Sheet1.Cells(22, 3).Value = "Done"
End Sub

Private Sub CommandButton3_Click()
EndNow = True
End Sub

Private Sub CommandButton4_Click() ' Write Wav file
Dim fs, f, filelen
Dim limit As Long, n As Long
Dim max As Single, min As Single, range As Single
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(ActiveWorkbook.Path + "\Excel.wav", True)
MsgBox "Sound written to " & ActiveWorkbook.Path + "\Excel.wav"

f.write "RIFF"
filelen = Sheet1.Cells(17, 4).Value + 36
'f.write Chr(&H64) ' file length - 8
'f.write Chr(&H1F)
'f.write Chr(&H0)
'f.write Chr(&H0)
f.write Chr(filelen Mod 256)
f.write Chr((filelen / 256) Mod 256)
f.write Chr((filelen / 256 / 256) Mod 256)
f.write Chr((filelen / 256 / 256 / 256) Mod 256)
f.write "WAVE"
f.write "fmt "
f.write Chr(16) ' Length of the fmt data (16 bytes)
f.write Chr(0)
f.write Chr(0)
f.write Chr(0)
f.write Chr(1) ' Format tag: 1 = PCM
f.write Chr(0)
f.write Chr(1) ' Channels: 1 = mono, 2 = stereo
f.write Chr(0)
f.write Chr(&H40) ' Samples per second: e.g., 8000
f.write Chr(&H1F)
f.write Chr(&H0)
f.write Chr(&H0)
f.write Chr(&H40) ' Sample rate * block align
f.write Chr(&H1F)
f.write Chr(&H0)
f.write Chr(&H0)
f.write Chr(1) ' channels * bits/sample / 8
f.write Chr(0)
f.write Chr(8) ' 8 or 16
f.write Chr(0)
f.write "data"
f.write Chr(Sheet1.Cells(17, 4).Value Mod 256)
f.write Chr((Sheet1.Cells(17, 4).Value / 256) Mod 256)
f.write Chr((Sheet1.Cells(17, 4).Value / 256 / 256) Mod 256)
f.write Chr((Sheet1.Cells(17, 4).Value / 256 / 256 / 256) Mod 256)

' Convert column A to voltage 0-255 and send
limit = Sheet1.Cells(17, 4).Value
max = Sheet1.Cells(1, 1).Value
min = Sheet1.Cells(1, 1).Value

For i = 1 To limit
If Sheet1.Cells(i, 1).Value max Then
max = Sheet1.Cells(i, 1).Value
End If
If Sheet1.Cells(i, 1).Value < min Then
min = Sheet1.Cells(i, 1).Value
End If
Next i

range = max - min

For i = 1 To Sheet1.Cells(17, 4).Value
f.write Chr(Round((Sheet1.Cells(i, 1) - min) / range * 255, 0))
Next i
f.Close
End Sub


"fugazi48" wrote:

Anyone know how to decode a wave file into it's two tables of data? I am
interested in coverting wave files to text. I think I have a macro somewhere
that writes a wave file, but I don't know how to reverse engineer it.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to play wave file in current directory yo beee Excel Programming 2 May 3rd 04 09:15 AM
Is it Possible to add a Wave file to VBA Frank Kabel Excel Programming 0 April 15th 04 02:37 PM
Is it Possible to add a Wave file to VBA Tom Ogilvy Excel Programming 0 April 15th 04 02:36 PM
Macro to Play Wave File yo beee Excel Programming 3 November 3rd 03 02:56 AM
Macro to play wave file yo beee Excel Programming 1 October 29th 03 11:42 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"