How to fit two voices together

Source: Internet
Author: User
Tags format definition

such as 1.wav and 2.wav, and finally merged into 3.wav.

---frmmain
' These don't have to be annotated, you see.

Private Sub Cmdbrowse_click (Index as Integer) ' control array the magical, absolutely! :-)
With Thecomdlg
If Index < 2 Then
. DialogTitle = "Open WAVE file"
. ShowOpen
Else
. DialogTitle = "Select WAVE file name to save output"
. Showsave
End If
If. FileName <> "Then
Txtwavefile (Index). Text =. FileName
. FileName = ""
End If
End with
End Sub

Private Sub Cmdexit_click ()
Unload Frmmain
End Sub

Private Sub Cmdmix_click ()
If txtwavefile (0). Text = "" Then
MsgBox "Please select the first WAVE audio file to mix! ",," error "
Exit Sub
End If
If txtwavefile (1). Text = "" Then
MsgBox "Please select a second WAVE audio file to mix! ",," error "
Exit Sub
End If
If Txtwavefile (2). Text = "" Then
MsgBox "Please select a file to save the mixed WAVE audio! ",," error "
Exit Sub
End If
If mixwavefile (txtwavefile (0). Text, Txtwavefile (1). Text, Txtwavefile (2). Text) Then
MsgBox "Mixed WAVE audio file successfully! ",," Prompt "
End If
Theprogbar.value = 0
End Sub

Private Sub Cmdunite_click ()
If txtwavefile (0). Text = "" Then
MsgBox "Please select the first WAVE audio file to be merged! ",," error "
Exit Sub
End If
If txtwavefile (1). Text = "" Then
MsgBox "Please select the second WAVE audio file to be merged! ",," error "
Exit Sub
End If
If Txtwavefile (2). Text = "" Then
MsgBox "Please select a file to save the merged WAVE audio! ",," error "
Exit Sub
End If
If unitewavefile (txtwavefile (0). Text, Txtwavefile (1). Text, Txtwavefile (2). Text) Then
MsgBox "merged WAVE audio file successfully! ",," Prompt "
End If
Theprogbar.value = 0
End Sub

Private Sub form_unload (Cancel as Integer)
If MsgBox ("Do you really want to quit this program?") ", vbOKCancel," confirm exit ") = Vbcancel Then
Cancel =-1
End If
End Sub
Useful to me [0] throw a brick [0] reference | Report | Management

daisy8675 daisy8675
This edition rating:
more medals
#6 Score: 0 replies.: 2004-12-06 10:54:36 '---BAS----------------
Option Explicit

Private Type wavefilehdr ' WAVE file header definition
Strfiletag as String * 4 ' "RIFF" flag
Lngfilelen as Long ' file length, excluding ' RIFF ' flag and its own length
Strfiletype as String * 4 ' WAVE ' logo
End Type

Private Type datablockhdr ' data block definition
Strblocktag as String * 4 ' data block name
Lngblocklen as Long ' data block length, excluding data block name and its own length
End Type

Public Type pcmwaveformat ' PCM format definition
wFormatTag as Integer ' format flag, PCM 1
Nchannels as Integer ' channel number
Nsamplespersec as Long ' sample rate
Navgbytespersec as Long ' data rate
nBlockAlign as Integer ' block alignment size, which is the smallest unit of waveform data
wBitsPerSample as Integer ' sample size
End Type

' Maximum buffer length
Public Const Maxbufferlen as Long = 1024

' Create a new FileSystemObject object to facilitate the operation of the file
Public Myfso as New FileSystemObject

' WAVE file Merge function
' File1 is the first file to be merged
' File2 for the second file to be merged
' OutFile files for merge output
Public Function Unitewavefile (File1 As String, File2 as String, OutFile as String) as Boolean
Dim FileName (1) as String
Dim FILEHDR (1) as Wavefilehdr
Dim BLOCKHDR (1) as Datablockhdr
Dim wavefmt (1) as Pcmwaveformat
Dim Readedformat (1) as Boolean
Dim Buffer () as Byte, I as Long
FileName (0) = File1
FileName (1) = File2
For I = 0 to 1
If not Myfso.fileexists (FileName (I)) Then
MsgBox "File:" "& FileName (I) &" "does not exist! Please re-enter the file name or select a file. ",," error "
Unitewavefile = False
Exit Function
End If
Open FileName (i) for Binary Access Read as # (i + 1)
Get # (i + 1), FILEHDR (i)
If Filehdr (i). Strfiletag <> "RIFF" Or filehdr (i). Strfiletype <> "WAVE" Then
MsgBox "File:" "& FileName (I) &" "is not a WAVE audio file! ",," error "
Close
Unitewavefile = False
Exit Function
End If
If Filehdr (i). Lngfilelen <> LOF (i + 1)-8 Then
MsgBox "File:" "& FileName (I) &" "is corrupted! ",," error "
Close
Unitewavefile = False
Exit Function
End If
Do Until EOF (I + 1) ' Loop until you read the "format" data block and the "waveform data" data size
Get # (i + 1), BLOCKHDR (i)
With BLOCKHDR (I)
If LOF (i + 1)-Loc (i + 1) <. Lngblocklen Then
MsgBox "File:" "& FileName (I) &" "is corrupted! ",," error "
Close
Unitewavefile = False
Exit Function
End If
If. Strblocktag = "FMT" and not Readedformat (I) Then
Get # (i + 1), wavefmt (i)
. Lngblocklen =. lngBlockLen-16
Readedformat (I) = True
If wavefmt (I). wFormatTag <> 1 Then
MsgBox "File:" "& FileName (I) &" "is not a PCM format! " _
& VbCrLf & "cannot be merged! ",," error "
Close
Unitewavefile = False
Exit Function
End If
End If
If. Strblocktag = "Data" and Readedformat (I) Then
Exit do
End If
Seek # (i + 1), Seek (i + 1) +. Lngblocklen
End with
Loop
Next
If wavefmt (0). Nchannels <> wavefmt (1). Nchannels Then
MsgBox "Two WAVE files are different in number of channels and cannot be merged! ",," error "
Close
Unitewavefile = False
Exit Function
End If
If wavefmt (0). wBitsPerSample <> wavefmt (1). wBitsPerSample Then
MsgBox "Two WAVE files are sampled in different sizes and cannot be merged! ",," error "
Close
Unitewavefile = False
Exit Function
End If
If wavefmt (0). Nsamplespersec <> wavefmt (1). Nsamplespersec Then
MsgBox "Two WAVE files have a different sampling rate and cannot be merged! ",," error "
Close
Unitewavefile = False
Exit Function
End If
On Error GoTo ErrorLine
If myfso.fileexists (OutFile) Then
Kill OutFile
End If
Open OutFile for Binary Access Write as #3
Put #3, "RIFF"
Put #3, 0&
Put #3, "WAVE"
Put #3, "FMT"
Put #3, 16&
Put #3, wavefmt (0)
Put #3, "data"
Put #3, BLOCKHDR (0). Lngblocklen + BLOCKHDR (1). Lngblocklen
FrmMain.TheProgBar.Min = 0
FrmMain.TheProgBar.Value = 0
FrmMain.TheProgBar.Max = BLOCKHDR (0). lngblocklen \ Maxbufferlen + BLOCKHDR (1). lngblocklen \ Maxbufferlen + 2
For I = 0 to 1
ReDim Buffer (MAXBUFFERLEN-1)
With BLOCKHDR (I)
While. Lngblocklen > 0
If. Lngblocklen > Maxbufferlen Then
. Lngblocklen =. Lngblocklen-maxbufferlen
Else
ReDim Buffer (. lngBlockLen-1)
. Lngblocklen = 0
End If
Get # (I + 1), Buffer
Put #3, Buffer
With Frmmain.theprogbar
If. Value <. Max Then
. Value =. Value + 1
End If
End with
Wend
End with
Next
Put #3, 5, LOF (3)-8
Close
Unitewavefile = True
Exit Function
ErrorLine:
If err.number > 0 Then
Close
MsgBox "Open File:" "& OutFile &" "Error, the file may have been opened by another program. "& _
VbCrLf & vbCrLf & Close the program to open this file or close the browser's preview of this file. ",," error "
Unitewavefile = False
End If
End Function

How to fit two voices together

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.