@@ -32,51 +32,51 @@ private void Button_Encode_Click(object sender, EventArgs e)
32
32
//Ensure that the file still exists
33
33
if ( File . Exists ( Textbox_EncodeFilePath . Text ) )
34
34
{
35
- using ( WaveFileReader fileReader = new WaveFileReader ( Textbox_EncodeFilePath . Text ) )
35
+ using ( WaveFileReader fileReader = new WaveFileReader ( Textbox_EncodeFilePath . Text ) )
36
+ {
37
+ if ( fileReader . WaveFormat . BitsPerSample == 16 && fileReader . WaveFormat . Encoding == WaveFormatEncoding . Pcm )
36
38
{
37
- if ( fileReader . WaveFormat . BitsPerSample == 16 && fileReader . WaveFormat . Encoding == WaveFormatEncoding . Pcm )
39
+ //Get PCM Data (in bytes)
40
+ byte [ ] pcmData = new byte [ fileReader . Length ] ;
41
+ fileReader . Read ( pcmData , 0 , ( int ) fileReader . Length ) ;
42
+
43
+ //Parse PCM Data to a short array
44
+ short [ ] samplesShort = new short [ pcmData . Length / 2 ] ;
45
+ WaveBuffer sourceWaveBuffer = new WaveBuffer ( pcmData ) ;
46
+ for ( int i = 0 ; i < samplesShort . Length ; i ++ )
38
47
{
39
- //Get PCM Data (in bytes)
40
- byte [ ] pcmData = new byte [ fileReader . Length ] ;
41
- fileReader . Read ( pcmData , 0 , ( int ) fileReader . Length ) ;
48
+ samplesShort [ i ] = sourceWaveBuffer . ShortBuffer [ i ] ;
49
+ }
42
50
43
- //Parse PCM Data to a short array
44
- short [ ] samplesShort = new short [ pcmData . Length / 2 ] ;
45
- WaveBuffer sourceWaveBuffer = new WaveBuffer ( pcmData ) ;
46
- for ( int i = 0 ; i < samplesShort . Length ; i ++ )
51
+ //Save File
52
+ SaveFileDialog . Filter = "Interactive Multimedia Association ADPCM File(*.ima)| *.ima" ;
53
+ SaveFileDialog . FileName = string . Join ( "" , Path . GetFileNameWithoutExtension ( Textbox_EncodeFilePath . Text ) , "_Encoded" ) ;
54
+ DialogResult saveFileDialog = SaveFileDialog . ShowDialog ( ) ;
55
+ if ( saveFileDialog == DialogResult . OK )
56
+ {
57
+ //Encode stereo
58
+ byte [ ] encodedData ;
59
+ if ( fileReader . WaveFormat . Channels == 2 )
47
60
{
48
- samplesShort [ i ] = sourceWaveBuffer . ShortBuffer [ i ] ;
49
- }
61
+ short [ ] [ ] splittedData = WavFunctions . SplitChannels ( samplesShort , 2 ) ;
62
+ byte [ ] encodedDataLeftChannel = ImaADPCM . EncodeIMA_ADPCM ( splittedData [ 0 ] ) ;
63
+ byte [ ] encodedDataRightChannel = ImaADPCM . EncodeIMA_ADPCM ( splittedData [ 1 ] ) ;
50
64
51
- //Save File
52
- SaveFileDialog . Filter = "Interactive Multimedia Association ADPCM File(*.ima)| *.ima" ;
53
- SaveFileDialog . FileName = string . Join ( "" , Path . GetFileNameWithoutExtension ( Textbox_EncodeFilePath . Text ) , "_Encoded" ) ;
54
- DialogResult saveFileDialog = SaveFileDialog . ShowDialog ( ) ;
55
- if ( saveFileDialog == DialogResult . OK )
65
+ encodedData = ImaADPCM . CombineChannelsIMA ( encodedDataLeftChannel , encodedDataRightChannel , 1 ) ;
66
+ }
67
+ //Encode mono
68
+ else
56
69
{
57
- //Encode stereo
58
- byte [ ] encodedData ;
59
- if ( fileReader . WaveFormat . Channels == 2 )
60
- {
61
- short [ ] [ ] splittedData = WavFunctions . SplitChannels ( samplesShort , 2 ) ;
62
- byte [ ] encodedDataLeftChannel = ImaADPCM . EncodeIMA_ADPCM ( splittedData [ 0 ] ) ;
63
- byte [ ] encodedDataRightChannel = ImaADPCM . EncodeIMA_ADPCM ( splittedData [ 1 ] ) ;
64
-
65
- encodedData = ImaADPCM . CombineChannelsIMA ( encodedDataLeftChannel , encodedDataRightChannel , 1 ) ;
66
- }
67
- //Encode mono
68
- else
69
- {
70
- encodedData = ImaADPCM . EncodeIMA_ADPCM ( samplesShort ) ;
71
- }
72
- File . WriteAllBytes ( SaveFileDialog . FileName , encodedData ) ;
70
+ encodedData = ImaADPCM . EncodeIMA_ADPCM ( samplesShort ) ;
73
71
}
72
+ File . WriteAllBytes ( SaveFileDialog . FileName , encodedData ) ;
74
73
}
75
- else
76
- {
77
- MessageBox . Show ( "Format not supported" , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
78
- }
79
74
}
75
+ else
76
+ {
77
+ MessageBox . Show ( "Format not supported" , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
78
+ }
79
+ }
80
80
}
81
81
}
82
82
0 commit comments