A software tool to identify unused Samples on the NS2

Everything about the Nord Stage series; features, specifications, how to operate, and questions about technical issues.
Post Reply
User avatar
Frantz
Patch Creator
Posts: 2261
Joined: 30 Apr 2011, 13:12
14
Your Nord Gear #1: Nord Electro 5
Location: ♫♪ earth ♪♫
Has thanked: 465 times
Been thanked: 550 times
Contact:
France

A software tool to identify unused Samples on the NS2

Post by Frantz »

Hello

This would be great if the Nord Sample Editor could display this information, maybe in a column on the sample table & panel.

WARNING : this is amateur work ! don't modify any of your Nord's file nor upload it back into the instrument, you could fairly loose your warranty and generate unnecessary work for Nord's support. My sense is that we do not have the right to reverse engineer a proprietary format and make business of it. We will only read some of the files, no write, no modification, no upload.


I did 3 synth sounds by pressing "sound init" and only changing the sample. I synchronized the files with Sound Manager.
The first "ns2s" file is using sample number 119, the second is using sample number 120 and the third is using sample number 121.
Then I compared the 3 "ns2s" files :
ns2s_hex.jpg
ns2s_hex.jpg (71.22 KiB) Viewed 2735 times
The changes that are underlined in red :
"EC" in hex value is 236 in decimal
"EE" is 238
"F0" is 240
may be the sample number.
I forgot to underline "E6" , "E7" and "E8", I think this corresponds to the synth programm number.
Maybe what I underlined in green is a checksum used to check if the format is OK, and I have no idea how it is computed. That would prevent me from modifying the file and think about loading it into the Nord.

If I take the 3 samples I used, I have this :
nsmp_hex.jpg
nsmp_hex.jpg (103.71 KiB) Viewed 2735 times
I would like to believe that the numbers I underlined with blue is the sample number.

Hanon remarked this :
If you divide those numbers by 2, they're 118, 119, 120
It works out if you apply a +1 offset for conversion from base 0 numbering.

I looked at the program files (ns2p).
I did 2 programs, with only one difference, one using sample number 120 and 121 for the other.
Then I compared the files :
ns2p_hex_diff.jpg
ns2p_hex_diff.jpg (110.97 KiB) Viewed 2735 times
EE is still 238 and F0 is still 240
I now have the bytes where I think the sample number are located.

The thing to try may look like that :

Code: Select all

- for each snmp file, read byte number 14 and 15 to get snmp_number
      - for each ns2s file, read byte number 30 and 31
              - divide by 2, add 1, if result == snmp_number then add snmp_number to used_list
      - for each ns2p file, read byte number 207 and 208
              - divide by 2, add 1, if result == snmp_number then add snmp_number to used_list

- print used_list
A byte being only 256 values, I may miss something because we can have more than 256 synth and snmp.
I did not tried with slot B.

I wrote the following program, it analyses the files and prints unused sample.
I compiles, it runs, it works like that :
unusedSamples.jpg
unusedSamples.jpg (25.51 KiB) Viewed 2735 times
It takes one argument on the command line : the path and filename of a zip file containing the files you synchronized using Nord Sound Manager.
I also work on a backup file, like in the screen shot (.ns2b).

Here is the source :

Code: Select all

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;


public class UnusedSamples {

	public static void main(String[] args) {
		try {

			ZipFile zf = new ZipFile(args[0]);
			List<Integer> unusedSamples = new ArrayList<Integer>();
			List<Integer> nsmpNumbers = scanNsmp(zf);
		        System.out.println("");
		        for (Integer nsmpNumber : nsmpNumbers) {
		    	      if (!scanNs2p(zf, nsmpNumber)) unusedSamples.add(nsmpNumber);
		        }
		        System.out.println("");
		        for (Integer _nsmpNumber : unusedSamples) System.out.print(_nsmpNumber+";");

		} catch (Throwable t) {
			t.printStackTrace();
		}

	}

    private static List<Integer> scanNsmp(ZipFile zf) {
		ZipEntry ze = null;
		List<Integer> nsmpNumbers = new ArrayList<Integer>();
		try {
			Enumeration<? extends ZipEntry> zes = zf.entries();
			while (zes.hasMoreElements()) {
				ze = zes.nextElement();
				if (ze.getName().endsWith(".nsmp")) nsmpNumbers.add(getNsmpNumberFromNsmp(zf.getInputStream(ze))); 		    	
			}
		} catch (IOException t) {
			if (ze!=null) System.out.println("Trying to read : "+ze.getName());
			t.printStackTrace();
		}
		return nsmpNumbers;
    }

    private static boolean scanNs2p(ZipFile zf, Integer nsmpNumber) {
		ZipEntry ze = null;
		try {
			Integer _nsmpNumber;
			Enumeration<? extends ZipEntry> zes = zf.entries();
		    while (zes.hasMoreElements()) {
		    	ze = zes.nextElement();
		    	if (ze.getName().endsWith(".ns2p")) {
		    		_nsmpNumber = getNsmpNumberFromNs2p(zf.getInputStream(ze));
		    		if (nsmpNumber.equals(_nsmpNumber)) return true;
		    	}
		    }
		} catch (IOException t) {
			if (ze!=null) System.out.println("Trying to read : "+ze.getName());
			t.printStackTrace();
		}
	    return false;
	}

    private static Integer getNsmpNumberFromNsmp(InputStream is) throws IOException {
		is.skip(14);
		int snmpNumber = is.read();
//		System.out.print(snmpNumber+":");
		return new Integer(snmpNumber);
	}

	private static Integer getNsmpNumberFromNs2p(InputStream is) throws IOException {
		is.skip(206);
		int b1 = is.read();
		int b2 = is.read();
		int _b1 = b1 & 0xF;
		int _b2 = b2 >> 4;
		int b = _b1*16+_b2;
//		System.out.print("["+_b1+":"+_b2+"] / 2 ="+b/2);
		return new Integer(b/2);
	}
}
Here is the binary and the source in a zip file :
UnusedSamples.zip
(2.86 KiB) Downloaded 332 times
I can add the scan for the ns2s files (synth progs).
I haven't looked at where sample number is located for slotB into ns2p files
I do not know how to do a user interface.
I'm sure a real programmer can go far further.

If you have any question, be welcome,

:wave:
Last edited by Frantz on 31 Jul 2012, 12:25, edited 3 times in total.
These users thanked the author Frantz for the post:
iaorana
http://displaychord.arfntz.fr
A mobile app to display chord names while you play, using midi / bluetooth connection.
User avatar
Johannes
Administrator
Posts: 2193
Joined: 05 Mar 2009, 01:04
16
Your Nord Gear #1: Nord Stage 2
Your Nord Gear #2: Other Brand
Location: Milano
Has thanked: 741 times
Been thanked: 844 times
Contact:
Italy

Re: A software tool to identify unused Samples on the NS2

Post by Johannes »

Hi frantzkb,

slot B would indeed be necessary to not miss out some samples that one cannot delete without harming ones' sounds.
But then this would really be a useful tool to keep one's sample memory clean and save space! Hope that is doable with Panel B as well - I would guess so even I could not yet find the appropriate offsets.
:clap: great job and hope to get it finished soon! :thumbup:
Last edited by Johannes on 31 Jul 2012, 12:25, edited 2 times in total.
Post Reply