|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Feb 01, 2015 1:29 pm Post subject: playing MP3 files with playSound [CE6.4] |
|
|
Code: | -- fix MemoryStream write, and add other useful methods
if oldcreateMemoryStream==nil then oldcreateMemoryStream = createMemoryStream end
function createMemoryStream()
local obj = oldcreateMemoryStream()
local oldwrite=obj.write
obj.write = function (t,n) -- override default write
local count=0
for _,v in ipairs(t) do
if count==n then break end
oldwrite({v},1)
count=count+1
end
end
obj.writeDword = function (v) obj.write(dwordToByteTable(v)) end
obj.writeWord = function (v) obj.write(wordToByteTable(v)) end
return obj
end
header = {
0x46464952,0x00000000,0x45564157,0x20746D66,0x0000001E,0x00020055,
0x0000AC44,0x00000020,0x00000001,0x0001000C,0x00000002,0x00010001,
0x61660571,0x00047463,0x2FF80000,0x61640014
} -- 44100Hz , Stereo
--convertMP3ToRIFFMP3(stream, stereo, rate)
--convertMP3ToRIFFMP3(stream) == convertMP3ToRIFFMP3(stream, true, 44100)
--convertMP3ToRIFFMP3(stream, false) == convertMP3ToRIFFMP3(stream, false, 44100)
function convertMP3ToRIFFMP3(stream, stereo, rate)
local riffmp3 = createMemoryStream()
for i,v in ipairs(header) do riffmp3.writeDword(v) end
riffmp3.writeWord(0x6174)
riffmp3.writeDword(stream.Size)
riffmp3.copyFrom(stream,stream.Size)
riffmp3.Position = 0x4; riffmp3.writeDword(stream.Size+0x24)
if stereo==false then riffmp3.Position = 0x16; riffmp3.writeWord(1) end
if tonumber(rate) then riffmp3.Position = 0x18; riffmp3.writeDword(rate) end
riffmp3.Position = riffmp3.Size - 1
return riffmp3
end
if oldplaySound==nil then oldplaySound=playSound end
function playSound(track, ...)
if track==nil then return end
local stream
if track.ClassName=='TMemoryStream' then stream=track else stream=track.Stream end
if streamSwapTable==nil then streamSwapTable = {} end
local ID=userDataToInteger(stream)
if streamSwapTable[ID]~=nil then oldplaySound(streamSwapTable[ID], ...) return end
stream.Position = 0
if table.concat(stream.read(4),'-')=='73-68-51-4' then
-- found mp3 file, converting
-- convertMP3ToRIFFMP3(stream, stereo, rate)
stream.Position = 0
local riffmp3 = convertMP3ToRIFFMP3(stream, true, 32000) -- ADJUST THIS LINE
streamSwapTable[ID]=riffmp3
oldplaySound(riffmp3, ...)
else
-- other file (wav)
streamSwapTable[ID]=stream
oldplaySound(stream, ...)
end
end |
If you are using different sample rate (e.g. 48000) and mono instead of stereo, change this line:
Code: | local riffmp3 = convertMP3ToRIFFMP3(stream) -- ADJUST THIS LINE |
to this:
Code: | local riffmp3 = convertMP3ToRIFFMP3(stream, false, 48000) -- ADJUST THIS LINE |
convertMP3ToRIFFMP3 has three parameters: stream, ifstereosettotrue, yourmp3samplerate.
convertMP3ToRIFFMP3(stream) is equal to convertMP3ToRIFFMP3(stream, true, 44100)
convertMP3ToRIFFMP3(stream, false) is equal to convertMP3ToRIFFMP3(stream, false, 44100)
Demo below:
Description: |
|
Download |
Filename: |
playSound mp3.ct |
Filesize: |
21.11 KB |
Downloaded: |
468 Time(s) |
_________________
|
|
Back to top |
|
|
tomtinhte How do I cheat? Reputation: 0
Joined: 27 Aug 2014 Posts: 8
|
Posted: Fri Feb 27, 2015 11:23 am Post subject: Re: playing MP3 files with playSound [CE6.4] |
|
|
mgr.inz.Player wrote: | Code: | -- fix MemoryStream write, and add other useful methods
if oldcreateMemoryStream==nil then oldcreateMemoryStream = createMemoryStream end
function createMemoryStream()
local obj = oldcreateMemoryStream()
local oldwrite=obj.write
obj.write = function (t,n) -- override default write
local count=0
for _,v in ipairs(t) do
if count==n then break end
oldwrite({v},1)
count=count+1
end
end
obj.writeDword = function (v) obj.write(dwordToByteTable(v)) end
obj.writeWord = function (v) obj.write(wordToByteTable(v)) end
return obj
end
header = {
0x46464952,0x00000000,0x45564157,0x20746D66,0x0000001E,0x00020055,
0x0000AC44,0x00000020,0x00000001,0x0001000C,0x00000002,0x00010001,
0x61660571,0x00047463,0x2FF80000,0x61640014
} -- 44100Hz , Stereo
--convertMP3ToRIFFMP3(stream, stereo, rate)
--convertMP3ToRIFFMP3(stream) == convertMP3ToRIFFMP3(stream, true, 44100)
--convertMP3ToRIFFMP3(stream, false) == convertMP3ToRIFFMP3(stream, false, 44100)
function convertMP3ToRIFFMP3(stream, stereo, rate)
local riffmp3 = createMemoryStream()
for i,v in ipairs(header) do riffmp3.writeDword(v) end
riffmp3.writeWord(0x6174)
riffmp3.writeDword(stream.Size)
riffmp3.copyFrom(stream,stream.Size)
riffmp3.Position = 0x4; riffmp3.writeDword(stream.Size+0x24)
if stereo==false then riffmp3.Position = 0x16; riffmp3.writeWord(1) end
if tonumber(rate) then riffmp3.Position = 0x18; riffmp3.writeDword(rate) end
riffmp3.Position = riffmp3.Size - 1
return riffmp3
end
if oldplaySound==nil then oldplaySound=playSound end
function playSound(track, ...)
if track==nil then return end
local stream
if track.ClassName=='TMemoryStream' then stream=track else stream=track.Stream end
if streamSwapTable==nil then streamSwapTable = {} end
local ID=userDataToInteger(stream)
if streamSwapTable[ID]~=nil then oldplaySound(streamSwapTable[ID], ...) return end
stream.Position = 0
if table.concat(stream.read(4),'-')=='73-68-51-4' then
-- found mp3 file, converting
-- convertMP3ToRIFFMP3(stream, stereo, rate)
stream.Position = 0
local riffmp3 = convertMP3ToRIFFMP3(stream, true, 32000) -- ADJUST THIS LINE
streamSwapTable[ID]=riffmp3
oldplaySound(riffmp3, ...)
else
-- other file (wav)
streamSwapTable[ID]=stream
oldplaySound(stream, ...)
end
end |
If you are using different sample rate (e.g. 48000) and mono instead of stereo, change this line:
Code: | local riffmp3 = convertMP3ToRIFFMP3(stream) -- ADJUST THIS LINE |
to this:
Code: | local riffmp3 = convertMP3ToRIFFMP3(stream, false, 48000) -- ADJUST THIS LINE |
convertMP3ToRIFFMP3 has three parameters: stream, ifstereosettotrue, yourmp3samplerate.
convertMP3ToRIFFMP3(stream) is equal to convertMP3ToRIFFMP3(stream, true, 44100)
convertMP3ToRIFFMP3(stream, false) is equal to convertMP3ToRIFFMP3(stream, false, 44100)
Demo below: |
I have tried with a mp3 files(128kbps) but without success
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Fri Feb 27, 2015 1:27 pm Post subject: |
|
|
Too few details. Provide more.
_________________
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|