# MP3 Editting



## hatman (Aug 19, 2013)

So I am wrestling with the additional security protocols that our Computer Services Vendor have applied to the latest platform they rolled out with the computer I got last month. Running Windows 7, and to install ANYTHING you need admin prviledges... along with this is a list of 7500+ software packages that our COmputer Services Vendor shall not install on any machine because of some legal mumbo-jumbo. Bottom line: I can't install MP3TagEdit, nor WavePad, nor any other psuedo-reputble, psuedo-useful freeware packages that allow editting of MP3 Tags, nor MP3 Audio Content. I overcame the Tag Edit challenge by writing some VBA code using the specifications available at ID3.org. Works well (though by no means exhaustively complete), and happy to share with anyone interested... That leaves me with no way to edit the MP3 audio content... really, all I want to be able to do is to be able to delete content from the beginning, end, or both and save what's left... I am toying with ripping into the MP3 binary encoding, and manipulating the raw data in VBA to get what I want... but smarter people than me have probably already done this and may even have VBA code available for sharing... any thoughts?


----------



## chuckchuckit (Aug 21, 2013)

Wow... that sounds like a bit of a task, or maybe should say a byte of a task. I've never worked with MP3 but done some mixing in the past with .wav files using Sonar6. Going after the binary encoding of the MP3 would have to be quite a lot of audio data even for a few seconds would imagine. Curious as to why you want to get rid of ends and just work with the middle portion? Do you want to modify the sound for your own type of mixing effects?

I have seen some experts here on MrExcel using VBA to handle serial communications data. They did it with ease it seemed and likely there would be some similarities there. John_w is one I think knows the serial data handling using VBA. Not sure how much of it might apply though.


----------



## hatman (Aug 21, 2013)

Why amputate sections of an MP3? I am a member of website that puts out several "talk radio" style podcasts each week, which I download to listen to while I work. Depending upon the DJ, the podcats vary in length from 1-3 hours, and each show is made up of individual segments varying in length from15 minutes to 1 hour each. Occassionally, I want to extract an individual song from amongst a file containing several songs and a bunch of talking, and then append Tag information, and add it to my library as an stand-alone file.

The file manipulations are't that bad... so far I have found a specification for the file format here (still exploring the other links).  Looks like each frame is 0.026 seconds long, so theoretically, as long as I split the file at frame boundaries, this should be manageable.  I think the most challenging part will be the user interface, and how to interpret the "audio content" of each frame in order to locate audio landmarks that will be used to determine where the splits should happen in the sequence.

It's progress...


----------



## chuckchuckit (Aug 27, 2013)

My wild guess on how I might approach it is: I'd need to be able to somehow listen to the audio while watching the data so I could cut and paste etc. Can't figure how I would do that with VBA but it would not be so hard to do with music mixing software such as years ago when I used Sonar6. I would RIP the song along with everything else into a .wav file that would then be imported into Sonar6. The whole song etc would be one long file you could see the .wav form of on the screen via Sonar6. Then cut, paste, modify (sound levels, frequencies, effects etc) right there. Your cutting out the ends and just saving the song would be pretty easy to do. But using VBA to somehow do it, I cannot see how it could cover your audible monitoring the data. Unless you did something along the lines of using something similar to Application.Speech.Speak?


----------



## hatman (Aug 28, 2013)

chuckchuckit said:


> My wild guess on how I might approach it is: I'd need to be able to somehow listen to the audio while watching the data so I could cut and paste etc. Can't figure how I would do that with VBA but it would not be so hard to do with music mixing software such as years ago when I used Sonar6. I would RIP the song along with everything else into a .wav file that would then be imported into Sonar6. The whole song etc would be one long file you could see the .wav form of on the screen via Sonar6. Then cut, paste, modify (sound levels, frequencies, effects etc) right there. Your cutting out the ends and just saving the song would be pretty easy to do. But using VBA to somehow do it, I cannot see how it could cover your audible monitoring the data. Unless you did something along the lines of using something similar to Application.Speech.Speak?



I have some ideas on how to display the graphical waveform directly in the cells.  I think I'll end up with vertical orientation rather than horizontal, but I can get used to it.  If I display the data from each 0.026 second frame in a row, then I have a maximum of 8 hours of audio that I display over 1.2 million rows... should be plenty. 

I haven't gotten far enough to figure out if a wrappered function like Application.Speech.Speak would work... probably not.  I fully anticipate using a WinAPI function call directly (Jafaar, this is your cue to chime in and offer advice <|;O)

Right now I am struggling to find any kind of detailed documentation on how the data in the audio frames in encoded... last night, I found this article http://blog.bjrn.se/2008/10/lets-build-mp3-decoder.html</SPAN>, which looks promising... have not had any time to delve into it and see if it's useful at all, and looks like it's blocked here at work.


----------



## chuckchuckit (Aug 28, 2013)

Using the gift of being creative can be fun. Interestingly, your link talks about ripping a .wav file. I'd have a hard time with the cells vertical orientation Excel might do if any .wav file visualizing was used, but could be transposed if did not run out of col's. Some sort of API call might work for "sampling" some sections of cells you could hear the content of for audio location monitoring. Actual looking at a .wav file can help with finding location of your song for instance in the whole section. You would be building your own kind of audio mixing software via VBA.


----------



## hatman (Aug 28, 2013)

Exactly.  It'll be rough, I admit, insofar as the user interface, visualization and audio will probably suck... but I am enjoying the challenge as a change of pace.  Who knows, it may turn out better than I expect.  I am reminded of a file that came across my radar screen about 8 years ago where someone had written Pac Man in VBA, using one worksheet cell as a pixel, and changing the background colors to generate the animation... it was neat just to see it done in that venue, even though there were no advantages, and even some detriments to the environment.


----------



## chuckchuckit (Aug 28, 2013)

I like doing that kind of stuff you are trying to do. Some people can really get into perfecting the details and become experts at it. Some like to take a concept and start putting that together which is how I kind of am, that bigger picture stuff, being creative. So I can totally relate to what you are trying to do. It sounds like fun and if I had the time I'd likely take a try at it some too.

Am off on vacation now, finally. Hope you keep us posted as I am curious how it might work.


----------



## hatman (Sep 17, 2013)

Haven't had a chance to touch this since my last post.  I have a pretty stable set of code that edits the Tags, which I "use" regularly.  No progess on parsing and editting the actual audio portion of a file, yet... I hope things around here slacken up a little bit soon.


----------



## iknowu99 (May 31, 2014)

hello hatman, have you figured out a way to edit mp3s in VBA?


----------



## hatman (May 31, 2014)

Alas, I have not had an opportunity to even look at this.  Rather frustrating, as I cannot install any sort of audio editing software in my machine at work, due to various security restrictions.  We've had a variety of staff reductions here, which has reduced my flexibility to play with fun stuff like this in my free time.  This is a long term project anyway.  you looking to help, or looking to "borrow"?  <|;O)


----------



## hatman (Jun 3, 2015)

An update for anyone following this:

1) I have accumulated a 3-ring binder full of printouts from various web resources, mostly doctoral thesis papers.  One of the annoying pieces of misinformation I have run into is the fact that someone somewhere along the lines asserted that every physical audio frame stores 1152 samples, and goes on to provide a simplified framesize calculation based on this assumption.  And almost every white-paper or article in existence blindly reprints this, perhaps because it's USUALLY true, or perhaps it's an oversight in favor of concentrating on more complex concepts.  For anyone who cares, this page gives just about the best info for decoding the header information for an physical frame: MPEG Audio Frame Header - CodeProject.

2) As hard as it was to figure out the header information, delving into the Side Information, which actually defines how the audio data is stored, is even more difficult to figure out.  One of the best online resources I have found was here: http://www.mp3-tech.org/programmer/docs/mp3_theory.pdf.  Right now, I am embroiled in decoding the side info, and using the Main_Data_Begin field to translate the Physical Audio Frames to Virtual Audio Frames, or a bitstream... not sure what is going to work out better.

3) After I have unpacked the audio frames, next comes the Huffman encoding.  Every resource explains the CONCEPT of Huffman Encoding in greater or lesser detail, because it is this encoding that actually reduces filesize by up to a factor 12 while still maintaining CD audio quality.  It uses 32  lookup tables to represent blocks of audio data, and finding those tables for download is almost impossible.  I finally located an open source software that contained the tables in a format I could work with: Index of /~ruckert/understanding_mp3/distribution/32bit.

4) I have gotten deep enough into this to realize that this project may be far too ambitious for my programming skills... or maybe for my patience, I don't know which.  I'm still pushing forward, as time allows, and each time I see a road-block in the distance, it seems to fall away as I get closer.


----------



## iknowu99 (Aug 17, 2015)

thanks for the post! I was curious about how shazam works (borrow) and if it would be possible to understand it through vba but we might need some reading up on sound engineering...


----------



## CheesyHome (Aug 21, 2015)

how can it would be possible to VBA ?
Thanks
Discover more architectural and interior design inspirations on
3D Home Interior Design | Office | Kitchen Rendering Studio


----------



## hatman (Aug 21, 2015)

CheesyHome said:


> how can it would be possible to VBA ?
> Thanks



Welcome to the BOARD!

I assume that you are questioning how one approaches this task in VBA.  Or perhaps any complex project that seems to be unrelated to Excel?  In a very real sense, VBA has most of the functionality of VB 6.0, making it a very powerful programming language, though uncompiled, so it does tend to run somewhat slow compared to code compiled to take advantage of multi-threading.  Any capability that is not intrinsically available within the VBA library can usually be accessed a) from another library, b) from the Windows API (Windows .dll files), or c) Built from scratch.  In the case of "playing music" one needs to communicate with the sound card.  So far, this looks like it will be one of the more difficult parts of this particular project... I haven't solved it yet, but I continue to research it, as time permits.  This is a long-term project that I am doing as a way to challenge myself.  It's an extension of a project I built several years ago that allows editing of ID3 Tags and embedding cover-art images in MP3 Files... all in Excel.


----------

