Hi,
I think my problem deals with class casting and inheritance.
I want to deal with various Audio Formats, reading into memory for
modification, working with it (done by different classes), and writing the
result to disk afterwards.
Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and
MP3FileIO and AuFileIO for the In/Out operations.
They all are inherited from the AudioFileIO class, because they all share
common methods like readSamples, writeSamples, readHeader, writeHeader.
Only the implementation is sometimes different.
Now, I want to use them in a let's say generic way:
[1]
while(there is data)
{
IN.readSamples(); // using the classes mentioned above
DelayEffect.work(); // modify the memory buffer(sample data)
OUT.writeSamples(); // using the classes mentioned above
}
But due to different audio formats, the type of the IN and OUT variable
depends on the desired audio format the user specifies.
I do not want to code every time many IF-THEN-ELSE statements for checking
the desired format and for using the proper variable.
Isn't it possible to check the audio format of the incoming audio material
at first and then casting the IN and OUT variable to the proper type of
audio class?
Like:
IF the incoming file is a WAV, then IN = Type of WaveFileIO
ELSE IF incoming file is a AIF, then IN = Type of AiffFileIO
// then using the code fragment [1], and other code fragments like [1]
Ciao, Michael 8 2022
Michael wrote: I think my problem deals with class casting and inheritance.
I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes), and writing the result to disk afterwards.
Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and MP3FileIO and AuFileIO for the In/Out operations. They all are inherited from the AudioFileIO class, because they all share common methods like readSamples, writeSamples, readHeader, writeHeader. Only the implementation is sometimes different.
Now, I want to use them in a let's say generic way:
[1] while(there is data) { IN.readSamples(); // using the classes mentioned above
DelayEffect.work(); // modify the memory buffer(sample data)
OUT.writeSamples(); // using the classes mentioned above }
But due to different audio formats, the type of the IN and OUT variable depends on the desired audio format the user specifies. I do not want to code every time many IF-THEN-ELSE statements for checking the desired format and for using the proper variable.
Isn't it possible to check the audio format of the incoming audio material at first and then casting the IN and OUT variable to the proper type of audio class? Like:
IF the incoming file is a WAV, then IN = Type of WaveFileIO ELSE IF incoming file is a AIF, then IN = Type of AiffFileIO
// then using the code fragment [1], and other code fragments like [1]
Your problem is in the incomplete design.
Apparently, all "Audio Formats" should derive from a common base class,
which should have the 'readSamples', 'writeSamples', and other functions
and you should be instantiating proper derived class object into a pointer
to the base class:
AudioFileIO *IN = 0;
switch (in_file_type) {
case WAVE: IN = new WaveFileIO(???);
break;
case AIFF: IN = new AiffFileIO(???);
break;
...
}
// similar for 'OUT'
Then you should use your 'IN' and 'OUT' pointers _polymorphically_. Read
about polymorphism, inheritance, abstract base classes, etc.. That's what
makes C++ well-suited for OOP -- class hierarchies.
Come back when you redesign your application with polymorphism in place.
V
Victor Bazarov wrote: AudioFileIO *IN = 0; switch (in_file_type) { case WAVE: IN = new WaveFileIO(???); break; case AIFF: IN = new AiffFileIO(???); break; ... }
Bad idea, I think that astract factory pattern is in place......
Michael wrote: Isn't it possible to check the audio format of the incoming audio material at first and then casting the IN and OUT variable to the proper type of audio class?
You might consider the "factory method" or "abstract factory" design
patterns.
On Fri, 6 Jan 2006 21:38:10 +0100, "Michael" <fe**@hrz.tu-chemnitz.de>
wrote: Hi,
I think my problem deals with class casting and inheritance.
Virtual functions sounds like the way to go.
I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes), and writing the result to disk afterwards.
Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and MP3FileIO and AuFileIO for the In/Out operations. They all are inherited from the AudioFileIO class, because they all share common methods like readSamples, writeSamples, readHeader, writeHeader. Only the implementation is sometimes different.
Now, I want to use them in a let's say generic way:
[1] while(there is data) { IN.readSamples(); // using the classes mentioned above
DelayEffect.work(); // modify the memory buffer(sample data)
OUT.writeSamples(); // using the classes mentioned above }
But due to different audio formats, the type of the IN and OUT variable depends on the desired audio format the user specifies. I do not want to code every time many IF-THEN-ELSE statements for checking the desired format and for using the proper variable.
Isn't it possible to check the audio format of the incoming audio material at first and then casting the IN and OUT variable to the proper type of audio class? Like:
IF the incoming file is a WAV, then IN = Type of WaveFileIO ELSE IF incoming file is a AIF, then IN = Type of AiffFileIO
// then using the code fragment [1], and other code fragments like [1]
Ciao, Michael
In addition to the Abstract Factory design pattern, the Strategy
pattern might serve you well for this.
--
Bob Hairgrove No**********@Home.com
puzzlecracker wrote: Victor Bazarov wrote:
AudioFileIO *IN = 0; switch (in_file_type) { case WAVE: IN = new WaveFileIO(???); break; case AIFF: IN = new AiffFileIO(???); break; ... }
Bad idea, I think that astract factory pattern is in place......
And inside that "abstract factory", what are you going to do? And if
that factory is abstract, how do you instantiate it? Through another
abstract factory? Think before you post your "bad idea" replies.
"Michael" <fe**@hrz.tu-chemnitz.de> wrote in message
news:dp**********@anderson.hrz.tu-chemnitz.de... Hi,
I think my problem deals with class casting and inheritance.
I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes), and writing the result to disk afterwards.
Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and MP3FileIO and AuFileIO for the In/Out operations. They all are inherited from the AudioFileIO class, because they all share common methods like readSamples, writeSamples, readHeader, writeHeader. Only the implementation is sometimes different.
Now, I want to use them in a let's say generic way:
[1] while(there is data) { IN.readSamples(); // using the classes mentioned above
DelayEffect.work(); // modify the memory buffer(sample data)
OUT.writeSamples(); // using the classes mentioned above }
But due to different audio formats, the type of the IN and OUT variable depends on the desired audio format the user specifies. I do not want to code every time many IF-THEN-ELSE statements for checking the desired format and for using the proper variable.
What, exactly, do you mean "the type of the IN and OUT variable depends on
the desired audio format the user specifies." Why isn't the IN and OUT
variables members of the audio formats themselves? Why aren't they just
functions? Why do they depend on the type of the desired audio format?
Where do IN and OUT get their data to work on?
It sounds like you just need polymorphism, but it could also be that you
need RTTI. I don't understand what you are trying to do in your code
snippet. You don't specify what type IN and OUT can be nor why you need
them.
I'm sure there's many ways to do what you want, but I don't understand what
it is you're trying to do. Isn't it possible to check the audio format of the incoming audio material at first and then casting the IN and OUT variable to the proper type of audio class? Like:
IF the incoming file is a WAV, then IN = Type of WaveFileIO ELSE IF incoming file is a AIF, then IN = Type of AiffFileIO
Using RTTI you can check the type of a polymorphic variable. But is this
what you are really needing to do? I'm just not sure.
In case you are, though, it would something like this:
if ( typeid( MyVar ) == typeid( MyClass ) )
so, for instance, if your polymorphic variable was stored in the variable
format it would be:
if ( typeid( Format ) == typeid( WaveFileIO ) )
although it might be a differernt if Format is a pointer. I *think* this
syntax is what you need (not positive)
if ( typeid( Format ) == typeid( WaveFileIO* ) ) // then using the code fragment [1], and other code fragments like [1]
Ciao, Michael This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: vrillusions |
last post by:
I've been using functions since I first started using php, but I've been
hearing more and more about classes, which I never really looked at that
much. I understand the whole OO programming...
|
by: Patrick Kowalzick |
last post by:
Dear all,
I just wondered if it is possible to count the number of classes created via
a template class at compile time.
To show what I mean I post an example, which is not working but carries...
|
by: Ramesh Tharma |
last post by:
Hi,
Is any one knows what's wrong with the following code, I was told that it
will compile and run but it will crash for some values.
Assume that variables are initilized.
char* c;
long*...
|
by: mharness |
last post by:
Hello All,
I've defined a number of classes that currently only include public variable
declarations. I've been reluctant to add subroutines and functions for fear
of taking a performance hit...
|
by: Shannon Richards |
last post by:
Hello: I am confused about casting...
Option Strict = ON
Example1:
---------------
When I say something like this...
Dim lo_Foo = New Foo
Dim lo_Obj as Object = lo_Foo
|
by: Enrique Bustamante |
last post by:
Casting arrays that works on watch and command window but not in code.
My application is casting arrays in a way it should work. To test if I
was doing something invalid, I wrote a test code that...
|
by: Spoon |
last post by:
Hello everyone,
I'm writing code where I can receive two kinds of packets.
The first 12 octets are common to both packet types, i.e. they have
the same semantics.
The 1st type has 4 more...
|
by: brekehan |
last post by:
I've always been a little sketchy on the differences between static,
dynamic, and reinterpret casting. I am looking to clean up the
following block by using C++ casting instead of the C style...
|
by: Ronald Raygun |
last post by:
If I have the following class heirarchy:
class A{
protected $m_type;
function type(){return $this->m_type;}
}
class B extends A{}
class C extends B{}
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
| |