Homebrew Homebrew Development

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,490
Country
United States
@catlover007 I had a thought last night. The resulting palette-like color from the method I use comes from GPU_FRAGMENT_SECONDARY_COLOR in the texture combiners, and while the source alpha value from a tex unit set with GPU_L8 is always 1.0, I wonder what I'd get if I attempted to read the source R/G/B from the tex unit, since it doesn't have an actual color value when it's GPU_L8....

I'd check it, but unfortunately, my compy decided to form a memory leak in a program, wasting all my RAM on boot, and is unusable for anything atm.
 

RocketRobz

Stylish TWiLight Hero
Developer
Joined
Oct 1, 2010
Messages
16,594
Trophies
3
Age
24
XP
20,993
Country
United States
I'm using this code to read the battery
Code:
            sf2d_texture *batteryIcon = battery0tex;    // Prevent crashing
            if(R_SUCCEEDED(PTMU_GetBatteryChargeState(&batteryChargeState)) && batteryChargeState) {
                sf2d_texture *batteryIcon = batterychrgtex;
            } else if(R_SUCCEEDED(PTMU_GetBatteryLevel(&batteryLevel))) {
                sf2d_texture *batteryIcon = battery5tex;
            } else {
                sf2d_texture *batteryIcon = battery0tex;
            }
but it doesn't work.
It's supposed to use the battery charging texture if the system is charging, and etc..
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
I'm using this code to read the battery
Code:
            sf2d_texture *batteryIcon = battery0tex;    // Prevent crashing
            if(R_SUCCEEDED(PTMU_GetBatteryChargeState(&batteryChargeState)) && batteryChargeState) {
                sf2d_texture *batteryIcon = batterychrgtex;
            } else if(R_SUCCEEDED(PTMU_GetBatteryLevel(&batteryLevel))) {
                sf2d_texture *batteryIcon = battery5tex;
            } else {
                sf2d_texture *batteryIcon = battery0tex;
            }
but it doesn't work.
It's supposed to use the battery charging texture if the system is charging, and etc..
You are creating a new sf2d_texture *batteryIcon for each condition.
 

RocketRobz

Stylish TWiLight Hero
Developer
Joined
Oct 1, 2010
Messages
16,594
Trophies
3
Age
24
XP
20,993
Country
United States
You are creating a new sf2d_texture *batteryIcon for each condition.
If I take out the line of code that's next to "Prevent crashing", the app will crash, as it's trying to draw a non-existent texture set to batteryIcon.

Changed the code a bit,
Code:
            if(R_SUCCEEDED(PTMU_GetBatteryChargeState(&batteryChargeState)) && batteryChargeState) {
                sf2d_texture *batteryIcon = batterychrgtex;
                batterytext = "Charging";
            } else if(R_SUCCEEDED(PTMU_GetBatteryLevel(&batteryLevel))) {
                sf2d_texture *batteryIcon = battery5tex;
                batterytext = "Level";
            } else {
                sf2d_texture *batteryIcon = battery0tex;
                batterytext = "Null";
            }
and when running the app, it always outputs "Null", regardless if battery is charging or not.
 
Last edited by RocketRobz,

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
If I take out the line of code that's next to "Prevent crashing", the app will crash, as it's trying to draw a non-existent texture set to batteryIcon.

Changed the code a bit,
Code:
            if(R_SUCCEEDED(PTMU_GetBatteryChargeState(&batteryChargeState)) && batteryChargeState) {
                sf2d_texture *batteryIcon = batterychrgtex;
                batterytext = "Charging";
            } else if(R_SUCCEEDED(PTMU_GetBatteryLevel(&batteryLevel))) {
                sf2d_texture *batteryIcon = battery5tex;
                batterytext = "Level";
            } else {
                sf2d_texture *batteryIcon = battery0tex;
                batterytext = "Null";
            }
and when running the app, it always outputs "Null", regardless if battery is charging or not.
You may want to google variable declarations and scope. Why are you doing sf2d_texture *batteryIcon=texture instead of batteryIcon=texture? The first one creates a new pointer variable. The second one assigns a value to an existing pointer. Your existing code assigns a pointer that immediately goes out of scope and is discarded without being used.
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,490
Country
United States
Does anyone know here if it's normal to hear a "clicking" sound when using ndsp audio? If yes, is there a fix? It is annoying
NDPS normally doesn't have clicking, so it may be your use of it. How are you using it? Audio streaming? If you could trim your project down into a test of your audio implementation with example audio that still has the clicking, zip it, then post it for us to examine, we'll be able to help you further.
 
  • Like
Reactions: cheuble

cheuble

squid
Member
Joined
Feb 6, 2016
Messages
746
Trophies
0
Age
22
Location
Fourside
XP
1,308
Country
France
NDPS normally doesn't have clicking, so it may be your use of it. How are you using it? Audio streaming? If you could trim your project down into a test of your audio implementation with example audio that still has the clicking, zip it, then post it for us to examine, we'll be able to help you further.
Sure thing! https://github.com/cheuble/NAMELESS/tree/master/source. The files are "sound.cpp" and "sound.h". If you want to test it, you'll need a data folder attached here. If you want, I can trim down the sound class to a simple project, if it is easier for you.
Data folder (extract to the root of your SD): https://filetrip.net/dl?LAAEtG6v9Z

EDIT: Here is a trimmed down version of the sound system. It It will simply loop an "example.wav" at the root of your SD card.
Code:
#include <3ds.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
ndspWaveBuf waveBuf;
u8* data = NULL;
using namespace std;
int playWav(string path, int channel = 1, bool toloop = true) {
  u32 sampleRate;
  u32 dataSize;
  u16 channels;
  u16 bitsPerSample;

  ndspSetOutputMode(NDSP_OUTPUT_STEREO);
  ndspSetOutputCount(2); // Num of buffers

  // Reading wav file
  FILE* fp = fopen(path.c_str(), "rb");

  if(!fp)
  {
  printf("Could not open the example.wav file.\n");
  return -1;
  }

  char signature[4];

  fread(signature, 1, 4, fp);

  if( signature[0] != 'R' &&
  signature[1] != 'I' &&
  signature[2] != 'F' &&
  signature[3] != 'F')
  {
  printf("Wrong file format.\n");
  fclose(fp);
  return -1;
  }

  fseek(fp,0,SEEK_END);
   dataSize = ftell(fp);
  fseek(fp, 22, SEEK_SET);
  fread(&channels, 2, 1, fp);
  fseek(fp, 24, SEEK_SET);
  fread(&sampleRate, 4, 1, fp);
  fseek(fp, 34, SEEK_SET);
  fread(&bitsPerSample, 2, 1, fp);

  if(dataSize == 0 || (channels != 1 && channels != 2) ||
  (bitsPerSample != 8 && bitsPerSample != 16))
  {
  printf("Corrupted wav file.\n");
  fclose(fp);
  return -1;
  }
  // Allocating and reading samples
  data = static_cast<u8*>(linearAlloc(dataSize));
  fseek(fp, 44, SEEK_SET);
  fread(data, 1, dataSize, fp);
  fclose(fp);

  fseek(fp, 44, SEEK_SET);
  fread(data, 1, dataSize, fp);
  fclose(fp);
  dataSize/=2;
  // Find the right format
  u16 ndspFormat;

  if(bitsPerSample == 8)
  {
  ndspFormat = (channels == 1) ?
  NDSP_FORMAT_MONO_PCM8 :
  NDSP_FORMAT_STEREO_PCM8;
  }
  else
  {
  ndspFormat = (channels == 1) ?
  NDSP_FORMAT_MONO_PCM16 :
  NDSP_FORMAT_STEREO_PCM16;
  }

  ndspChnReset(channel);
  ndspChnSetInterp(channel, NDSP_INTERP_NONE);
  ndspChnSetRate(channel, float(sampleRate));
  ndspChnSetFormat(channel, ndspFormat);

  // Create and play a wav buffer
  std::memset(&waveBuf, 0, sizeof(waveBuf));

  waveBuf.data_vaddr = reinterpret_cast<u32*>(data);
  waveBuf.nsamples = dataSize / (bitsPerSample >> 3);
  waveBuf.looping = toloop;
  waveBuf.status = NDSP_WBUF_FREE;

  DSP_FlushDataCache(data, dataSize);

  ndspChnWaveBufAdd(channel, &waveBuf);

  return ((dataSize / (bitsPerSample >> 3)) / sampleRate); // Return duration in seconds, for debugging purposes

}
int main(int argc, char* argv[]){

   gfxInitDefault();
   ndspInit();
   consoleInit(GFX_TOP, nullptr);
   ndspChnWaveBufClear(1);
   playWav("sdmc:/example.wav");
  while(aptMainLoop())
   {
     hidScanInput();

     u32 keys = hidKeysDown();
     if(keys & KEY_START)
       break;

     gfxFlushBuffers();
     gfxSwapBuffers();
     gspWaitForVBlank();
  }
   gfxExit();
   ndspExit();
   return 0;

}
 
Last edited by cheuble,

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
Sure thing! https://github.com/cheuble/NAMELESS/tree/master/source. The files are "sound.cpp" and "sound.h". If you want to test it, you'll need a data folder attached here. If you want, I can trim down the sound class to a simple project, if it is easier for you.
Data folder (extract to the root of your SD): https://filetrip.net/dl?LAAEtG6v9Z

EDIT: Here is a trimmed down version of the sound system. It It will simply loop an "example.wav" at the root of your SD card.
Code:
#include <3ds.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
ndspWaveBuf waveBuf;
u8* data = NULL;
using namespace std;
int playWav(string path, int channel = 1, bool toloop = true) {
  u32 sampleRate;
  u32 dataSize;
  u16 channels;
  u16 bitsPerSample;

  ndspSetOutputMode(NDSP_OUTPUT_STEREO);
  ndspSetOutputCount(2); // Num of buffers

  // Reading wav file
  FILE* fp = fopen(path.c_str(), "rb");

  if(!fp)
  {
  printf("Could not open the example.wav file.\n");
  return -1;
  }

  char signature[4];

  fread(signature, 1, 4, fp);

  if( signature[0] != 'R' &&
  signature[1] != 'I' &&
  signature[2] != 'F' &&
  signature[3] != 'F')
  {
  printf("Wrong file format.\n");
  fclose(fp);
  return -1;
  }

  fseek(fp,0,SEEK_END);
   dataSize = ftell(fp);
  fseek(fp, 22, SEEK_SET);
  fread(&channels, 2, 1, fp);
  fseek(fp, 24, SEEK_SET);
  fread(&sampleRate, 4, 1, fp);
  fseek(fp, 34, SEEK_SET);
  fread(&bitsPerSample, 2, 1, fp);

  if(dataSize == 0 || (channels != 1 && channels != 2) ||
  (bitsPerSample != 8 && bitsPerSample != 16))
  {
  printf("Corrupted wav file.\n");
  fclose(fp);
  return -1;
  }
  // Allocating and reading samples
  data = static_cast<u8*>(linearAlloc(dataSize));
  fseek(fp, 44, SEEK_SET);
  fread(data, 1, dataSize, fp);
  fclose(fp);

  fseek(fp, 44, SEEK_SET);
  fread(data, 1, dataSize, fp);
  fclose(fp);
  dataSize/=2;
  // Find the right format
  u16 ndspFormat;

  if(bitsPerSample == 8)
  {
  ndspFormat = (channels == 1) ?
  NDSP_FORMAT_MONO_PCM8 :
  NDSP_FORMAT_STEREO_PCM8;
  }
  else
  {
  ndspFormat = (channels == 1) ?
  NDSP_FORMAT_MONO_PCM16 :
  NDSP_FORMAT_STEREO_PCM16;
  }

  ndspChnReset(channel);
  ndspChnSetInterp(channel, NDSP_INTERP_NONE);
  ndspChnSetRate(channel, float(sampleRate));
  ndspChnSetFormat(channel, ndspFormat);

  // Create and play a wav buffer
  std::memset(&waveBuf, 0, sizeof(waveBuf));

  waveBuf.data_vaddr = reinterpret_cast<u32*>(data);
  waveBuf.nsamples = dataSize / (bitsPerSample >> 3);
  waveBuf.looping = toloop;
  waveBuf.status = NDSP_WBUF_FREE;

  DSP_FlushDataCache(data, dataSize);

  ndspChnWaveBufAdd(channel, &waveBuf);

  return ((dataSize / (bitsPerSample >> 3)) / sampleRate); // Return duration in seconds, for debugging purposes

}
int main(int argc, char* argv[]){

   gfxInitDefault();
   ndspInit();
   consoleInit(GFX_TOP, nullptr);
   ndspChnWaveBufClear(1);
   playWav("sdmc:/example.wav");
  while(aptMainLoop())
   {
     hidScanInput();

     u32 keys = hidKeysDown();
     if(keys & KEY_START)
       break;

     gfxFlushBuffers();
     gfxSwapBuffers();
     gspWaitForVBlank();
  }
   gfxExit();
   ndspExit();
   return 0;

}
Your dataSize variable includes the size of the header. So you are playing past the data read from the wav file. You are also not correctly accounting for stereo when computing the number of samples, but that is not likely contributing to your current issue.
 

cheuble

squid
Member
Joined
Feb 6, 2016
Messages
746
Trophies
0
Age
22
Location
Fourside
XP
1,308
Country
France
Your dataSize variable includes the size of the header. So you are playing past the data read from the wav file. You are also not correctly accounting for stereo when computing the number of samples, but that is not likely contributing to your current issue.
I see, any fixes for this? I'm not experienced with this, I just used an example. To bypass the stereo issue, I added a simple if(channels == 2){dataSize/=2;}
I know it's not the way to do this but.... Anyway, do you know how I should do this?
EDIT: It seems like the problem does NOT come from the header, but from the end of the file, which DOES contain informations:
fbp2xQX.png
 
Last edited by cheuble,

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
I see, any fixes for this? I'm not experienced with this, I just used an example. To bypass the stereo issue, I added a simple if(channels == 2){dataSize/=2;}
I know it's not the way to do this but.... Anyway, do you know how I should do this?
EDIT: It seems like the problem does NOT come from the header, but from the end of the file, which DOES contain informations:
fbp2xQX.png
As I said you are including the header in the size. So you are attempting to read past the end of the file. Which ends up just playing the uninitialized space at the end of your buffer. This is here is a more complete example to parse wav files - https://github.com/elhobbs/spectre3ds/blob/master/source/wav_parser.cpp
 

cheuble

squid
Member
Joined
Feb 6, 2016
Messages
746
Trophies
0
Age
22
Location
Fourside
XP
1,308
Country
France
As I said you are including the header in the size. So you are attempting to read past the end of the file. Which ends up just playing the uninitialized space at the end of your buffer. This is here is a more complete example to parse wav files - https://github.com/elhobbs/spectre3ds/blob/master/source/wav_parser.cpp
I don't think it is parsing the header. According to the official WAV documentation, the header size is 44 bytes long. My code is doing that:
Code:
  fseek(fp, 44, SEEK_SET);
  fread(data, 1, dataSize, fp);
  fclose(fp);
So there shouldn't be any issues. Plus, the clicking sound is gone now, the problem was the wav file. Thanks for your help anyway
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,033
Country
United States
I don't think it is parsing the header. According to the official WAV documentation, the header size is 44 bytes long. My code is doing that:
Code:
  fseek(fp, 44, SEEK_SET);
  fread(data, 1, dataSize, fp);
  fclose(fp);
So there shouldn't be any issues. Plus, the clicking sound is gone now, the problem was the wav file. Thanks for your help anyway
That is good that you reaolved the issue. But it looks like you are using ftell to get the dataSize which will include the size of the header.
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
Yeah, sure, but when I want to use other fonts (in my case "Press Start 2P"), the result looks...

So is there a fix for this? Or should I edit the font?

What's wrong with this font?

In the past I had some problems with sftd printing text in different sizes (bigger sizes resulted with blurring and other defects). Don't know if this is the problem you are refferring to, but the trick to bypass this problem is to initialize the font with the larger size you plan to use.
 

erman1337

Well-Known Member
Member
Joined
Sep 27, 2015
Messages
1,211
Trophies
0
Location
Brussels
XP
983
Country
Belgium
Yeah, sure, but when I want to use other fonts (in my case "Press Start 2P"), the result looks...
IXGKt5p.png

pRtkObO.png

moxrvHt.png

So is there a fix for this? Or should I edit the font?
You can use images instead, that's what I do

If the font is monospaced (all the glyphs have the same width & height), you could make a tileset of the font and write a renderer function
 
Last edited by erman1337,

cheuble

squid
Member
Joined
Feb 6, 2016
Messages
746
Trophies
0
Age
22
Location
Fourside
XP
1,308
Country
France
What's wrong with this font?

In the past I had some problems with sftd printing text in different sizes (bigger sizes resulted with blurring and other defects). Don't know if this is the problem you are refferring to, but the trick to bypass this problem is to initialize the font with the larger size you plan to use.
Yeah, that's the problem, if you zoom in the images, you can notice that the text is all weird (blank squares appearing, blur, not at the same space, etc...). How do I initialize a font with a size? The only thing I see is "sftd_font *sftd_load_font_file(const char *pathname);", and this doesn't take any parameters referring to the size.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    BakerMan @ BakerMan: @salazarcosplay yeah cod's still up