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

Pages: 1

Parduz
Reged: 01/08/08
Posts: 30
Loc: Bologna, ITALY
Send PM


How do i use util::wav_open and wav_close?
#395292 - 12/12/22 04:53 PM


I have problems using the wavwrite functions.

I open the files this way (actually stoled from sounds.cpp)

Code:


m_wavraw = util::wav_open("raw.wav", m_sample_rate, 2);



but then i get compile errors:

Code:


util::wav_close(*m_wavraw);


throws "error: cannot convert 'util::wav_file' to 'util::wav_file*"


Code:


util::wav_close(m_wavraw);


throws "error: cannot convert 'util::wav_file_ptr' {aka 'std::unique_ptr'} to 'util::wav_file*' "

How am i supposed to close that file?



MooglyGuy
Renegade MAME Dev
Reged: 09/01/05
Posts: 2258
Send PM


Re: How do i use util::wav_open and wav_close? new [Re: Parduz]
#395299 - 12/14/22 05:51 AM


> How am i supposed to close that file?

By being able to look at the existing code that uses those functions.



Parduz
Reged: 01/08/08
Posts: 30
Loc: Bologna, ITALY
Send PM


Re: How do i use util::wav_open and wav_close? new [Re: MooglyGuy]
#395303 - 12/14/22 07:11 PM


> > How am i supposed to close that file?
>
> By being able to look at the existing code that uses those functions.
I guess it's a blessing being smart like you!!!
Problem is no one uses the wav_close function. They all flush everything when mame closes.
Thanks for your AWESOME help.



MooglyGuy
Renegade MAME Dev
Reged: 09/01/05
Posts: 2258
Send PM


Re: How do i use util::wav_open and wav_close? new [Re: Parduz]
#395304 - 12/14/22 11:28 PM


> > > How am i supposed to close that file?
> >
> > By being able to look at the existing code that uses those functions.
> I guess it's a blessing being smart like you!!!
> Problem is no one uses the wav_close function. They all flush everything when mame
> closes.
> Thanks for your AWESOME help.

It really is a blessing being smart like me.

Because I'm smart, I can read, and I can code. Because I can read, I can see that on line 28 in wavwrite.h, there is a line that says:


Code:


using wav_file_ptr = std::unique_ptr;



Because I can code, I can tell that an asterisk - * - is the "pointer" operator in C and C++, and so the most likely scenario is that "wave_file_ptr" is what I should be using in stead of "wave_file *".

And since I'm still able to read, I can go and look up the shitload of information that exists about std::unique_ptr. And since I can read that information, I can understand that I should be calling .reset() on the wave_file_ptr, and that trying to call wave_close manually is a stupid thing to do, and trying to do so would indicate that I'm a complete idiot - like you - who can neither read, nor code.

Stick to what you're good at. I don't know what you're good at - maybe ditch digging, or mopping floors - but whatever it is, it certainly isn't reading, or coding. Not when you're completely incapable of understanding straightforward compiler errors, and your first reaction is "It must be everyone else who is wrong".



Parduz
Reged: 01/08/08
Posts: 30
Loc: Bologna, ITALY
Send PM


Re: How do i use util::wav_open and wav_close? new [Re: MooglyGuy]
#395306 - 12/15/22 12:11 AM



> It really is a blessing being smart like me.
I concour.
Also, you're not efficent, and neither kind.
You could have explained this all in your first reply, and we could have been both happy in half of the time.

> Stick to what you're good at. I don't know what you're good at - maybe ditch digging,
> or mopping floors - but whatever it is, it certainly isn't reading, or coding.
Well, i was able to dump the ROMs of my old SQ1, and more or less to try to make the layout working to a minimum.
'cause my job is to program in c old microprocessors, and to squeeze every nanosecond of cycle from them.
So, i can understand logic, what i lack is a deep knowledge of modern c++, 'cause i never use it.

> Not when you're completely incapable of understanding straightforward compiler errors,
> and your first reaction is "It must be everyone else who is wrong".
This is somewhat i need to ask for pardon. My english is self-taught, so i'm sorry if what i said gives the impression that everyone else was wrong. I asked for help 'cause i cannot understand how to use something that
1) was clearly well established
2) but the existing code of the esq driver was using wrong, so i needed to understand what it was.

This being said, thanks for the clear explanation and the magnificent show of your ego. You can return to shine on your own altair knowing that today you helped a poor paesant. How great.



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? new [Re: Parduz]
#395307 - 12/15/22 09:47 AM


Dude, let’s think about this for a moment:

  • When you look at wavfile.h you see it has a wav_deleter class with a call operator that calls wav_close if the argument is not null.
  • The wav_file_ptr is declared as a unique_ptr involving wav_file and wav_file_deleter – looking up what a unique_ptr does would probably be a good idea.
  • Various MAME developers run MAME under memory analysers (e.g. Firewave and me). If everything was leaking wav_file we’d be screaming.



Parduz
Reged: 01/08/08
Posts: 30
Loc: Bologna, ITALY
Send PM


Re: How do i use util::wav_open and wav_close? new [Re: Vas Crabb]
#395308 - 12/15/22 10:45 AM


> Various MAME developers run MAME under memory analysers (e.g. Firewave and me). If
> everything was leaking wav_file we’d be screaming.
I NEVER said that there was something wrong in anything. I said that i had problems using it, asking about how to.

in esq5505.cpp the wav_file is used as it was even before being moved into /lib/util, there was a call to wav_close, and i tried to make it works, not understanding what a unique_ptr is (actually not knowing it at all) as long as 3/4 of the mame things used/instantiated/declared in that driver (or device ... whatever).
Anyway, i searched the whole src folder for wav_close and (now obviously) i've found nothing, if not equally outdated debugging code #defined out.
Should i've searched for reset()? Now that i know, yes. I didn't understood, so

I

JUST

ASKED

how to use it, got sarcasm as an aswer, replied with equal sarcasm, got "idiot" back *, replied with sarcasm.

Geez.


* dunno what are the forum rules about personal insults but no problem, i'm old enough to handle it.



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? new [Re: Parduz]
#395312 - 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.”



Parduz
Reged: 01/08/08
Posts: 30
Loc: Bologna, ITALY
Send PM


Re: How do i use util::wav_open and wav_close? new [Re: Vas Crabb]
#395313 - 12/15/22 05:23 PM


uh .... i think i'm not able to explain myself.

> Dude, I’m trying to help you learn to help yourself here.
I've understood it, don't get me wrong.
In my first reply to you i tried to explain how my mind sticked to the idea that i had to call that funtion: i saw it in old code, i trusted it should work that way today. The last time i looked at that source file was in 2016, i just tought i should ... "trust" what was there already. I was not debating about anything.

So i apreciated your reply.
I've also understood how it works after the first explanation and now that part works (at least, the file management, now i have to understand how the sound_stream_update works, but that's another story).


> 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.
I'm sorry to frustrate you, 'cause -i repeat- i apreciated your first reply, and i was just trying to explain and ... justify myself telling why i fell in that "trap".

> 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.”
You know, i'd like to been able to compose phrases like that. I can read and understand them, but when i have to SAY something i can't always come out this way and the result is a sort of "raw" english.

I'm sorry i haven't been clear, and that i give the impression i was ... blaming someone or something; what i meant was exactly what you said. Still, i think i did'nt deserve the sarcasm from the other guy.

Thanks for your explanation. Really.


Pages: 1

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

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