0

I need to translate this C# code from NReplayGain library here https://github.com/karamanolev/NReplayGain to a working VBNET code.

TrackGain trackGain = new TrackGain(44100, 16);
foreach (sampleSet in track) {
    trackGain.AnalyzeSamples(leftSamples, rightSamples)
}
double gain = trackGain.GetGain();
double peak = trackGain.GetPeak();

I've translate this:

Dim trackGain As New TrackGain(samplerate, samplesize)

Dim gain As Double = trackGain.GetGain()
Dim peak As Double = trackGain.GetPeak()
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 3
    There are a few good online translation options. What have you tried? Have you seen this [SO Post](http://stackoverflow.com/questions/10477697/how-to-get-sound-data-sample-value-in-c-sharp) on NAudio? – Stinky Towel Nov 16 '13 at 13:35
  • The foreach instruction could not be translated by any online service because the "value" inside parentheses is not a value/variable then the translator should return an EOF error. I didn't founded that NAudio question (thanks for the info) but the thing is that lib seems that was written only for Audio programmer Gurus and Masters, is not any easy-of-use, any intuitive, is really hard, I need an example of someone who knows how to touch that lib to retrieve the mp3 file sample data (using Naudio or not). thanks. PS: Sorry for my English. – ElektroStudios Nov 16 '13 at 13:48
  • you get to translate all the library for this – Hichem Nov 16 '13 at 14:00
  • This question appears to be off-topic because it is about doing your code translation – rene Dec 25 '13 at 20:45
  • @rene code translation is not an offtopic or taboo question in SO, you can see the existing tag about code translations, anyways my question was solved time ago then why saying that comment now?. thanks for read bye – ElektroStudios Dec 25 '13 at 22:43

3 Answers3

3

Use an online converter. C# to VB converters:

Your c# code shown above has errors. Probably it is written in pseudo code. I have not found any declaration of a sample set at the github address you mentioned.

A semicolon is missing (inside the loop). The loop variable sampleSet is not declared. Where do leftSamples and rightSamples come from? The loop variable is not used inside the loop. Probably the left and right samples are part of the sampleSet. If I correct this, I can convert the code by using one of these online converters.

C#:

TrackGain trackGain = new TrackGain(44100, 16);
foreach (SampleSet sampleSet in track) {
    trackGain.AnalyzeSamples(sampleSet.leftSamples, sampleSet.rightSamples);
}
double gain = trackGain.GetGain();
double peak = trackGain.GetPeak();

VB:

Dim trackGain As New TrackGain(44100, 16)
For Each sampleSet As SampleSet In track
    trackGain.AnalyzeSamples(sampleSet.leftSamples, sampleSet.rightSamples)
Next
Dim gain As Double = trackGain.GetGain()
Dim peak As Double = trackGain.GetPeak()

After all, the two versions don't look that different!

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • thankyou, the code of my question is as is in the webpage, yes was obvious that those "sampling" words are pseudocode it reffers to auido sample data of an audio file, I just needed to translate the syntax with that pseudo words like you did, thanks again. – ElektroStudios Nov 16 '13 at 14:51
  • I think is better if I edit my original question and do a new question for the NAudio part – ElektroStudios Nov 16 '13 at 14:52
2

It is fairly simple to reference within assemblies written in different languages. I frequently reference C# code from F# and have referenced VB.NET code from C#. Just be sure to compile both projects to target the same framework version, say .NET 4.5 or Mono 2.10 , and CPU architecture.

If you need the files to reside in the same assemblies. I would suggest you study the C# syntax and convert it manually.

Edit: After browsing the Repository, I only see a handful of classes. Besides learning new languages is a great way to improve both your ability to write code and read code in the languages you are already comfortable with.

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
  • Thankyou for the info, but I feel sorry I think that you miss-interpreted the question or my words, I don't need to reference C# projects, I have compiled the NAudio library then I can use it in VBNET, the code of my question is a little piece of code (and that's all) from other library which is a really little library and the ppurpose of that lib is to calculate the replaygain of a file, but for that first I need to retirve the necessary data from an mp3 file using the GIANT NAudio lib. thanks – ElektroStudios Nov 16 '13 at 14:47
1

A good one online solution to translate .NET to C# and vice-versa, to another language, as JavaScript is CodeTranslator - Carlossag. Until now, I didn't have problems with this translator.

Community
  • 1
  • 1
Bruno Freire
  • 157
  • 11
  • 1
    That translator is inefficient and/or obsolete, has many fails translating, and it does not properly translate interpolated strings. I found the best solution out there is **Instant C#** and **Instant VB** from **Tangible** software, it is a paid software but a lot more better than all free online solutions, much more efficient than **Telerik Code Converter**, which I consider it the best free solution (less inefficient than the other free solutions). – ElektroStudios Jun 05 '20 at 01:36