MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Flat Mode Flat  

Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4461
Loc: Melbourne, Australia
Send PM
Re: How do i use util::wav_open and wav_close?
12/15/22 03:46 PM


Dude, I’m trying to help you learn to help yourself here.

So you discovered that code behind if 0 has a habit of rotting. Great! That’s what happens to code that’s never compiled. It’s part of the reason logmacro.h is the way it is – it ensures logging code is compiled even when it’s disabled, and just optimised out, so we know the expressions are valid at the very least.

When you searched the source and didn’t find any uses of wav_close that aren’t in rotted code behind #if 0, you should have made the connection and realised that you aren’t supposed to call wav_close directly at all. Rather than continuing barking up the wrong tree, you could have found a place that uses wav_open and looked at how it used the returned object.

The first one I found with a simple grep was in the sound manager (src/emu/sound.cpp). It uses wav_open to open a file for recording:

Code:

bool sound_manager::start_recording(std::string_view filename)
{
if (m_wavfile)
return false;
m_wavfile = util::wav_open(filename, machine().sample_rate(), 2);
return bool(m_wavfile);
}


Now if we search the rest of this source file for m_wavfile, what can we turn up:

Code:

void sound_manager::stop_recording()
{
// close any open WAV file
m_wavfile.reset();
}



Code:

    ...
// play the result
if (finalmix_offset > 0)
{
if (!m_nosound_mode)
machine().osd().update_audio_stream(finalmix, finalmix_offset / 2);
machine().osd().add_audio_to_recording(finalmix, finalmix_offset / 2);
machine().video().add_sound_to_recording(finalmix, finalmix_offset / 2);
if (m_wavfile)
util::wav_add_data_16(*m_wavfile, finalmix, finalmix_offset);
}
...


Will you look at that! A commented line where it closes the WAV file, and a place where it appends samples. At no point did I need to know how a unique_ptr works, or search for reset.

Alternatively, you could have looked at the header where the WAV file writing functions are declared, seen that wav_open returns a std::unique_ptr, and then looked up what it is. Fortunately, the C++ standard library is well-specified, and there’s a great site with detailed documentation for most of it that ranks pretty high in web search results.

The question you asked initially was already based on a flawed assumption. You’d assumed that you’re supposed to call wav_close, and asked how to do that. The simple answer is that you don’t directly call wav_close at all. In your next reply, you say, “Problem is no one uses the wav_close function. They all flush everything when MAME closes.” This also isn’t true – they don’t call wav_close but they very much aren’t relying on things being flushed when MAME closes. Besides resource leaks, you wouldn’t be able to hard reset machines when using the wav_write option if that were the case. You could’ve initially asked how to close a WAV file, and you could’ve reexamined your assumptions after the first sarcastic response.

Now I’m pretty old, cynical and jaded. When I saw your initial question based on a flawed assumption and lack of investigation, I figured it wouldn’t be worth responding. Your reply with the second flawed assumption reinforced my opinion. I used to try to bend over backwards to be helpful, but experience has taught me that if people jump to flawed conclusions before even asking their initial question and then double down on it, trying to help them is just going to be a frustrating, unrewarding experience.

You would’ve got a better reaction from developers with an initial question more along the lines of, “How do I close a WAV file opened with util::wav_open? I figured I should call wav_close, but no currently compiling code does that.”







Entire thread
Subject Posted by Posted on
* How do i use util::wav_open and wav_close? Parduz 12/12/22 04:53 PM
. * Re: How do i use util::wav_open and wav_close? MooglyGuy  12/14/22 05:51 AM
. * Re: How do i use util::wav_open and wav_close? Parduz  12/14/22 07:11 PM
. * Re: How do i use util::wav_open and wav_close? MooglyGuy  12/14/22 11:28 PM
. * Re: How do i use util::wav_open and wav_close? Parduz  12/15/22 12:11 AM
. * Re: How do i use util::wav_open and wav_close? Vas Crabb  12/15/22 09:47 AM
. * Re: How do i use util::wav_open and wav_close? Parduz  12/15/22 10:45 AM
. * Re: How do i use util::wav_open and wav_close? Vas Crabb  12/15/22 03:46 PM
. * Re: How do i use util::wav_open and wav_close? Parduz  12/15/22 05:23 PM

Extra information Permissions
Moderator:  Pi 
0 registered and 16 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 216