Live data from Hacker News

Windows CoreAudio API in C#

hardkjarni.blogspot.com

1–10 of 30 posts

Re: Windows CoreAudio API in C#

#2
From the title, I wondered how to call Mac OS X's "Core Audio" (https://en.m.wikipedia.org/wiki/Core_Audio, https://developer.apple.com/library/mac/documentation/MusicA...) from Windows. My best guess was that QuickTime, or iTunes ship with DLLs implementing it for Windows.

Turns out a bit of a disappointment for the hacker in me. Windows has an API with the same name (https://msdn.microsoft.com/en-us/library/windows/desktop/dd3...)

Re: Windows CoreAudio API in C#

#3
post #2

From the title, I wondered how to call Mac OS X's "Core Audio" ( https://en.m.wikipedia.org/wiki/Core_Audio , https://developer.apple.com/library/mac/documentation/MusicA... ) from Windows. My best guess was that QuickTime, or iTunes ship with DLLs implementing it for Windows. Turns out a bit of a disappointment for the hacker in me. Windows has an API with the same name ( https://msdn.microsoft.com/en-us/library/win…

Hahaha, indeed. I didn't realize myself until I started looking into this that MS named the system in Vista the same as the Apple team did in Panther. :) Guess it is the nerd in us all wanting to be working on the "Core" stuff

Re: Windows CoreAudio API in C#

#4
The code is well structured and easy to read. Thanks for the example.

Random aside: Why do so many C# coders use #region/#endregion? It really seems like a bad habit that discourages otherwise good coders from splitting their code into logical OOP silos and instead they dump too much code into a single file, and then use regions to regain some kind of order...

Regions are like goto in that they don't within their own right do anything "bad" they just encourage really bad habits, and people start to think about things in terms of regions. Plus finding things in a project which contains tons of really long code files with regions is immensely harder than finding them in a project with a lot of isolated classes and decent inheritance.

Re: Windows CoreAudio API in C#

#5

The code is well structured and easy to read. Thanks for the example. Random aside: Why do so many C# coders use #region/#endregion? It really seems like a bad habit that discourages otherwise good coders from splitting their code into logical OOP silos and instead they dump too much code into a single file, and then use regions to regain some kind of order... Regions are like goto in that they don't within their own…

I don't get C# regions, either. At least Visual Studio makes it easy to auto-expand them and effectively ignore them while jumping around with incremental search and goto definition. Admittedly, this would be a problem if the rest of the team cared about maintaining the regions.

Re: Windows CoreAudio API in C#

#6

The code is well structured and easy to read. Thanks for the example. Random aside: Why do so many C# coders use #region/#endregion? It really seems like a bad habit that discourages otherwise good coders from splitting their code into logical OOP silos and instead they dump too much code into a single file, and then use regions to regain some kind of order... Regions are like goto in that they don't within their own…

Thanks for the kind words :) Yeah regions are a strange beast in C#. In some cases I find them handy, like in this instance where I wanted the COM interfaces embedded in the main class file. Also to clearly separate which functions belong to the manipulation of master vs individual program audio levels.

The region paradigm is very often misused and is one of those things that starts off nice and then degrades as time goes on (meaning new functions get added in the wrong region, refactorings end up all over the place, etc). I prefer them though over partial classes (shudder) and when properly used they can be a huge timesaver when dealing with those annoying UBER-Forms that tend to happen when dealing with legacy WinForms code :)

Re: Windows CoreAudio API in C#

#7
post #5

The code is well structured and easy to read. Thanks for the example. Random aside: Why do so many C# coders use #region/#endregion? It really seems like a bad habit that discourages otherwise good coders from splitting their code into logical OOP silos and instead they dump too much code into a single file, and then use regions to regain some kind of order... Regions are like goto in that they don't within their own…

I don't get C# regions, either. At least Visual Studio makes it easy to auto-expand them and effectively ignore them while jumping around with incremental search and goto definition. Admittedly, this would be a problem if the rest of the team cared about maintaining the regions.

I admit that sometimes I find them handy to use when dealing with large complex files. Grouping together member variables, events, statics can help with reducing the initial noise when opening the file (these tend to be at the top of the class usually).

But they indeed depend on the team's total commitment on keeping them organized and up-to-date.

Re: Windows CoreAudio API in C#

#8

The code is well structured and easy to read. Thanks for the example. Random aside: Why do so many C# coders use #region/#endregion? It really seems like a bad habit that discourages otherwise good coders from splitting their code into logical OOP silos and instead they dump too much code into a single file, and then use regions to regain some kind of order... Regions are like goto in that they don't within their own…

From sibling post: > when dealing with those annoying UBER-Forms that tend to happen when dealing with legacy WinForms code :)

This is similar to my experience.

I use regions pretty often when I'm refactoring overgrown legacy code, especially older MVC apps (where the controllers get insane)

Basically what you said, but reversed. I use regions as a first step to regaining some kind of order, then continue to pull things apart into more properly factored classes, methods, etc. It helps me mentally map things out. Of course there're a bunch of ways you could do that, but Visual Studio has good support for folding regions, so I prefer it.

That folding is the second reason I'll use them sometimes. If I have a really awkward part of code that I'd like to fold for whatever reason, I'll occasionally use them if I think it'll make things more readable.

I agree with the idea, though. Every time I use a region I have to stop and think "am I just hiding bad design?"

Re: Windows CoreAudio API in C#

#9
post #8

The code is well structured and easy to read. Thanks for the example. Random aside: Why do so many C# coders use #region/#endregion? It really seems like a bad habit that discourages otherwise good coders from splitting their code into logical OOP silos and instead they dump too much code into a single file, and then use regions to regain some kind of order... Regions are like goto in that they don't within their own…

From sibling post: > when dealing with those annoying UBER-Forms that tend to happen when dealing with legacy WinForms code :) This is similar to my experience. I use regions pretty often when I'm refactoring overgrown legacy code, especially older MVC apps (where the controllers get insane) Basically what you said, but reversed. I use regions as a first step to regaining some kind of order, then continue to pull thi…

>older MVC apps (where the controllers get insane).

Oh dear lord the MVC madness I've seen... thousand yard stare

Re: Windows CoreAudio API in C#

#10
post #9
post #8

Earlier quoted context omitted.

From sibling post: > when dealing with those annoying UBER-Forms that tend to happen when dealing with legacy WinForms code :) This is similar to my experience. I use regions pretty often when I'm refactoring overgrown legacy code, especially older MVC apps (where the controllers get insane) Basically what you said, but reversed. I use regions as a first step to regaining some kind of order, then continue to pull thi…

>older MVC apps (where the controllers get insane). Oh dear lord the MVC madness I've seen... thousand yard stare

I hear you. Seven year old MVC forms with five pages of inputs, backed up to a single forty column table via Entity Framework, and a controller with another five pages of arcane conditionals for binding and validations :|
Post reply on HN